Object Oriented Programming Flashcards
Object-Oriented Programming (OOP)
Paradigm where the program is composed of interacting objects, each responsible for its own data and operations
Class
Template for an object that defines its attributes and methods
Object
A specific instance of a class
Attribute
Data associated with the class
Method
A functionality of a class
Object state
The actual data values of a particular object’s attributes
Instantiation
Creation of a new object
How to instantiate object
By calling class’s constructor method → Object returned can be assigned to identifier variable
Types of methods
- Getter methods
- Setter methods
Getter methods
Written as functions and return the object’s state
Setter methods
Written as procedures and used to change object’s state
Encapsulation
Wrapping all of an object’s related data and methods under one entity → Objects can’t affect the way other objects function
Benefits of encapsulation
- Promotes modularity → Self-contained units of functionality that can be re-used
- Reduces complexity (easier to understand how object fits into system if it’s self-contained)
- Can change implementation of entity without impacting other parts of program
- Improve security (information hiding)
- Easier to maintain and test code (easier to interface with individual components)
Inheritance
- Principle that allows us to create a new class that is a modified version of another class
- Subclass gains all the attributes and methods of the superclass
- Subclasses can be overidden and properties can be polymorphised
- New data and behaviour can also be added to subclasses
When to used inheritance
- Is [subclass] a [superclass]?
- E.g. is a Fox an Animal?