Unit 2 OOP Cornell (1) Flashcards
(145 cards)
What are the key features of OOP?
- Classes
- Objects
- Encapsulation
- Abstraction
- Inheritance
- Generalisation
- Polymorphism
These features define the principles and structure of Object-Oriented Programming.
What is a class in OOP?
Blueprints for creating objects with predefined attributes and methods
A class defines the structure and behaviour of objects, such as a Person class with attributes like name and methods like walk.
What is an object in OOP?
Instances of classes that encapsulate data and behaviour
For example, a Person object may have attributes like name, age, gender, and occupation.
What is encapsulation in OOP?
Bundling data and methods within objects to restrict access and ensure data integrity
Encapsulation helps in preventing unintended interference with an object’s data.
What is a constructor method in OOP?
A special method in a class that initializes attributes when an object is created
In Python, it’s defined with the name __init__.
What is an instance in OOP?
A specific realization of a class created at runtime
Each instance has its own set of attributes and methods, independent of other instances.
What is abstraction in OOP?
Hiding complex implementation details and exposing only necessary functionalities
Abstraction simplifies the interface for users, allowing them to interact without needing to understand the complexities.
What is inheritance in OOP?
A mechanism for creating new classes based on existing ones, promoting code reuse and hierarchy
Sub-classes can inherit attributes and methods from their parent class.
What is generalisation in OOP?
Identifying common traits among a set of entities and extracting them into a generalised super-class
It reduces redundancy by creating a broader framework that captures shared attributes.
What is polymorphism in OOP?
The ability for objects of different types to be accessed through the same interface
It allows the same method to behave differently depending on the object that calls it.
What is procedural programming?
A programming paradigm focused on writing procedures or functions that operate on data
It organizes code around sequential execution of instructions.
How does OOP differ from procedural programming?
OOP organizes code around objects and their interactions, while procedural programming focuses on functions and procedures
This leads to more modular, reusable, and maintainable code in OOP.
What is the role of access modifiers in OOP?
Keywords that set the accessibility of classes, methods, and other members to enforce encapsulation
Examples include public, private, and protected.
What is the top-down approach in procedural programming?
Starting with a high-level overview of tasks and breaking them down into smaller, specific functions
It outlines the main steps before detailing each step.
What is a key disadvantage of procedural programming regarding data access?
It does not use access modifiers, allowing all parts of the program to access all data freely
This can lead to potential security risks and unintended interference.
What is the bottom-up approach in OOP?
Designing the system from specific objects and their behaviours to more complex systems
This contrasts with the top-down approach used in procedural programming.
What are the main features of Object-oriented programming (OOP)?
- Bottom-up approach
- Program is divided into objects
- Makes use of access modifiers
- More secure
- Object can move freely within member functions
- Supports inheritance
These features contribute to the modular and reusable nature of OOP.
What are the main features of Procedural-oriented programming (POP)?
- Top-down approach
- Program is divided into functions
- Doesn’t use access modifiers
- Less secure
- Data can move freely from function to function
These features define the structure and flow of procedural programming.
What does access to data in a program imply?
All parts of the program can access all data without restrictions
Why is unrestricted access to data considered less secure?
It can lead to unintended interference or misuse, increasing security risks
How does data move within programs?
Data is passed around between functions as parameters, allowing any function to manipulate any piece of data
What is a key limitation of procedural programming related to function organization?
It does not support inheritance, making each function a separate entity
What is Object Oriented Programming (OOP)?
A programming paradigm that emphasizes organizing code around objects, which are instances of classes
List some applications of OOP languages.
- Computer Games
- Web-based database applications
- Desktop Applications
- Mobile Applications
- Enterprise Software
- Scientific Computing
- Machine Learning and AI
- Data Analysis and Visualization
- Network and System Administration Tools