object oriented programming Flashcards
class
A class is a template for an object and defines the state and behaviour of an object
attributes
Data stored inside a class or object.
Methods
A set of instructions that complete a task, associated with an object
Information hiding
the process of hiding all details of an object that do not contribute to its essential characteristics
information hiding
private members
Some programming languages provide mechanisms to designate certain attributes or methods as “private,” meaning they can only be accessed within the same class or object. This prevents external code from directly manipulating or accessing these internal details.
Encapsulation
- Encapsulation is the bundling of data with the methods that operate on and restrict direct access to it.
- It is used to hide the values or internal state of an object, preventing direct access by unauthorised parties.
- Encapsulated attributes of an object should only be accessible or changeable via the methods provided by the object.
*
Inheritance
allows a class (called a subclass or derived class) to inherit all the methods and attributes of another class (called a superclass or base class) which can have its own additional properties. This concept allows programmers to effectively reuse certain components and properties while making some changes.
Polymorphism
means objects can behave differently depending on their class.
This can result in the same method producing different outputs depending on the object involved.
There are two categories of polymorphism: overriding and overloading.
polymorphism
overiding
Overriding (dynamic polymorphism) is redefining a method within a subclass and altering the code so that it functions differently and produces a different output.
polymorphism
overloading
Overloading (static polymorphism) is passing in different parameters into a method.