Object-Oriented Programming Flashcards
(30 cards)
What is object-oriented programming?
An entirely modular to programming where everything in the program is implemented as an object which has attributes and properties (data) and methods (subroutines)
What is encapsulation?
Data and subroutines for a single object are kept together and the data is controlled via methods that comprise the object’s interface
What is a class?
The definition that continues what attributes and methods an object will have
What is an object?
A specific instance of a class
What is encapsulation in terms of object-oriented programming?
Combining a record with the procedures and functions that manipulate it to form a new data type (class)
What is the constructor of a class?
The method called to instantiate an object of that class. There is an object that is returned from this and it can be stored in a variable
What is information hiding?
Protecting an object’s internal state from being accessed by other parts of the program
What are the access modifiers and how can they be represented in UML diagrams?
Public: +
Private: -
Protected: #
What does the public access modifier mean?
Attribute or method can be accessed by objects of any other class within the program
What does the private modifier mean?
Attribute or method can only be accessed by objects of the same class
What does the protected modifier mean?
Attribute or method can be accessed by objects of the same class or other classes that inherit from it
What is the format of a formal class definition?
ClassIdentifier = Class
Public
public attributes : types
public methods and procedures
Protected
protected attributes : types
protected methods
Private
private attributes : types
private methods
End
What is the default for attributes and methods?
Private attributes and public getter methods
What is inheritance in object-oriented programming?
A relationship between classes where a derived class gains the attributes and methods of the base class that it inherits from
How to represent inheritance in a UML diagram?
Arrow pointing from derived to base class
How to represent inheritance in a formal class definition?
DerivedClassIdentifier = Class (BaseClassIdentifier)
- only give additional methods in the definition or overriden methods
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 polymorphism (AQA definition)?
Polymorphism occurs when objects of different classes respond differently to the use of a common interface
What are virtual methods?
Methods that can be overriden in inheritance
What is method overriding?
Derived class inherits a method from the base class but implements it in a different way
What are the key differences between virtual and abstract methods?
Virtual methods:
- Can be overridden by a child class
- Are implemented
- Can be declared in any class
Abstract methods:
- Must be overridden by a child class
- Have no implementation in the parent class
- Can only be declared in abstract classes
How to declare an abstract class in C# and abstract method?
Abstract keyword
What are the two types of association?
1) Aggregation - “weak”
2) Composition - “strong”
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.