Object-Oriented Programming Flashcards
(36 cards)
What is a class?
The definition of an object. Classes define the attributes and methods that an object of the class will have.
What is an object?
A specific instance of a class
What is instantiation?
The process of creating an instance of an object, belonging to a class, by invoking a constructor method
What is encapsulation? (in terms of OOP)
Combing data with the procedures and functions that manipulate it to form a new data type (class)
What is information hiding in oop?
Protects an object’s implementation and internal state from being accessed by other objects
What are the uses of information hiding?
Allows programmers to implement restrictions on how values are accessed and set. This is done through the use of access modifiers.
What are the access modifiers and their descriptions?
- Public: accessed by objects of any other class (+)
- Private: accessed only by objects of that class (-)
- Protected: accessed by other objects of the class or subclass (#)
What is a getter method?
A method that returns the requested attribute value
What is a setter method?
A method that can modify the attribute’s value
Why do we use getters and setters?
They allow developers to implement additional checks before accepting or providing data.
What is polymorphism?
When objects of different classes respond differently to the use of a common interface
What is polymorphism in OOP?
Polymorphism occurs when an inherited method (in a subclass) is redefined or overriden so that its implementation is different from its parent
What is the interface?
The collection of a classes public methods, attributes and its identifier
What is overriding?
- When a method is defined in a derived class with the same identifier as a method from the base class but is given a different implementation/ performs a different function
- Redefined method will be used instead of the base’s method when called
What are methods that can be overridden by a derived class called?
Virtual methods
What does an abstract method define?
The interface:
- identifier
- return type
- list of parameters
What are the differences between a virtual and abstract class?
- Virtual methods can be overridden by a child class but abstract must be overridden by a child class
- Virtual have an implementation in base class but abstract do not
- Virtual can be declared in any class but abstract can only be defined in abstract classes
What is object association?
Occurs when an object contains or has a reference to another object within it. Often described as a “has a” relationship.
What are the two forms of association?
- Composition - “strong”
- Aggregation - “weak”
What is composition?
Composition is a restricted form of association, where one object contains another. If the container object is deleted, the contained objects are also deleted.
How is composition represented in a UML diagram?
A line between the two classes with a black filled diamond at the class which is the container (e.g. car to a wheel)
What is aggregation?
Type of relationship where one class contains another class.However, the aggregated objects exist independently of the aggregating object and will not be deleted from the program if the aggregating object is deleted.
How is aggregation represented in a UML diagram?
A line between the two classes and a white unfilled diamond at the aggregating object (e.g. car for a driver).
What is inheritance?
Describes the relationship between classes where a derived “child” class gains the attributes and methods from a “parent” class