Object-Oriented Programming (OOP)

Classes

  • Blueprints for creating objects.

Abstract Classes

  • The purpose is to provide a common definition of a base class that multiple derived classes can share;

  • Allow to declare methods without implementation. These methods must be implemented in the child class;

  • Abstract classes cannot be instantiated;

  • Abstract classes must be extended.

Objects

  • Instances of a class.

Interfaces

  • A class can implement multiple interfaces;

  • Interfaces contain only abstract methods (methods without implementation);

  • Interfaces cannot contain attributes.

Inheritance

  • A class can inherit attributes and methods from another class;

  • The parent class is extended, and child class extends the parent;

  • Private attributes and methods are not inherited;

  • Specialization is achieved by extending a class. The extending class is called child;

  • Generalization is achieved by combining classes into another one. The combined class is called parent.

Composition

  • A class can contain objects of other classes as attributes.

  • We can "inject" dependencies by requiring an argument as an instance of another class.

Encapsulation

  • Set visibility to attributes & methods.

Abstraction

  • Abstract classes cannot be instantiated.

  • Abstract classes must be extended.

  • Allow to declare methods without implementation. These methods must be implemented in the child class.

Polymorphism

  • Change the behaviour of an extended class by overriding methods.

Last updated