OOP Flashcards
what is meant by overriding?
When a derived class / subclass has a different implementation for a method / function / subroutine to the class it inherits from / from the base class;
what is meant by polymorphism?
A method shared (up and down the inheritance hierarchy chain) but with each class / method implementing it differently
//
A single interface is provided to entities/objects of different classes / types
//
Objects of different classes / types respond differently to the use of a common interface / the same usage
//
Allowing different classes to be used with the same interface
//
The ability to process objects differently depending on their class / type;
A protected attribute
protected attributes can also be accessed by any classes that inherit from the class they belong to;
Protected means it can be accessed / seen in the class it is in and in any subclasses // protected means it can be accessed / seen in the class it is in and in any classes derived / inheriting from it;
A private attribute
Private attributes can only be accessed by the class
What is meant by aggregation?
An object that contains other objects;
features of an object
Contains its own data/fields/variables/properties;
Contains its own Operations/methods/functions/procedures/behaviours/code;
Responds to messages;
What is meant by inheritance?
A class has properties/fields/attributes/characteristics and methods/procedures/functions of the parent class it is derived from
//
a subclass/derived class inherits all the properties/fields/attributes/characteristics and methods/procedures/functions from a super-class/base-class/parent class;
From an older paper:
Relationship among classes wherein one class shares the data structure and behaviour/methods / procedures / functions / actions of another class
OR when a class has the same characteristics as its parent class
State advantages of the object-oriented approach to program design over the structured approach to program design.
Produces re-useable code because of inheritance/encapsulation;
Produces re-useable objects;
Data is protected // only accessible in well-defined ways (because of encapsulation);
More efficient to write programs which use pre-defined / inherited objects / classes;
Storage structure of data and method code of a class may be altered without affecting programs that make use of the class;
Code produced contains fewer errors / more reliable;
Solutions are easier to understand (when expressed in terms of objects);
Easier to enforce design consistency; easier to debug;
Less maintenance effort required by developer since objects can be re-used;
New functions can be added to objects easily (because of inheritance);
What is meant by class?
A class
A grouping of data structures and behaviours / methods / procedures / functions; A set of objects / object type which share a common data structure and common behaviour / methods / procedures / functions;
Need both structure and behaviour
virtual method
Virtual methods can be overridden by the derived class //
virtual methods do not have to be overridden //
Virtual methods have an implementation/body //
virtual methods contain code (with functionality) (in the base class) //
virtual methods can be declared in abstract and non-abstract classes;
abstract method
abstract methods must be overridden by the derived class;
abstract methods do not contain an implementation/body //
abstract methods contain no code (with functionality) (in the base class) //
abstract methods only contain a declaration (in the base class);
Abstract methods can only be declared in abstract classes
A public attribute
Public means it can be accessed / seen outside of the class it is in;
Information hiding
[textbook] This principle of information hiding, where other classes cannot directly access the attributes of another class when they are declared private.