OOP Flashcards
What is OOP?
OOP is a programming methodology that considers a program as consisting of objects that interact with each other by means of actions
What is an object?
An object is an identifiable entity that has a set of attributes, behaviour and state
Name the basic units of an object-oriented system
Objects
Define attributes
Attributes are individual characteristics that differentiate one object from another
Define behaviour
Behaviour is defined by the set of actions an object can perform
Define state
State is defined by the set of values held by its attributes
What are member variables or instance variables?
While implementing a real-world object in software form, all its attributes are represented through data items known as member variables or instance variables
What are member methods?
While implementing a real-world object in software form, all its behaviors are represented through data items known as member methods
In a software object, sum up the attribute+behavior+state
Member variables that hold the attributes
The values of these variables define the state of obj
Member methods that define the behavior of obj
What is a class?
A class is a template or blueprint for multiple objects with similar features and may be regarded as a specification for creating similar objects
Which objects are grouped together in a class?
Objects that share the same attributes and behavior are grouped together in a class
Why is a class called an object factory?
A class is a blueprint for multiple objects with similar features and may be regarded as a specification for creating similar objects
What do you need to do to create objects belonging to a class?
Once a class has been defined, you can create many objects belonging to that class
What is known as an instance of a class?
An object belonging to a particular class is known as an instance of a class
State the differences between a class and an object
- The way attributes and methods are treated in the class and the object
- The class is just a specification of the object. The attributes and methods in the class are thus declarations that do not contain any values. However, an object is a concrete instance of a class with properly defined values of each attribute and behaves as per the methods of a class
In one line, summarize the specification difference between object and class
The class is a logical construct whereas the object has a physical reality.
Name the four fundamental principles of OOP
- Abstraction
- Encapsulation
- Inheritance
- Polymorphism
Define abstraction
Abstraction refers to the act of representing essential features without including the background details
Define encapsulation
Encapsulation is a mechanism that binds the data and code (methods) together into a single unit.
How does encapsulation promote protection of data?
Encapsulation keeps the data and methods safe from the outside world, preventing any unauthorized access or misuse. Access to the data and code inside a class is strictly controlled. Only the methods inside the class can access the data.
In a camera, where do abstraction and encapsulation come into play?
The Capture button shows the essential feature and not the details - abstraction
The encapsulation helping to hide all the internal details of taking a photograph - opening the aperture, streaming light through lens, etc
How do objects encapsulate state and behavior?
- An object stores its state in member variables and exposes its behavior through member methods.
- The member methods operate on member variables and serve as the primary mechanism to interact with the object.
- Only the member methods which are defined inside the class can access the data and change its state.
- Hence, the state and behavior are said to be encapsulated by the object, hiding the internal state and requiring all interactions to be performed through the methods of the object.
How can the data of an object be accessed and its state changed?
Only the member methods which are defined inside the class can access its data and change its state
Define inheritance
Inheritance is a powerful mechanism by which one class acquires the property of another class