Oop Key Terms and Principles
Oop Key Terms and Principles
Object-oriented programming is a model that organizes software We can create a new class based on existing class. The new class
design around objects which interact with each other. can reuse the code and behavior of the ancestor class, and it can
also add new features or modify the existing behavior.
Basic terms Types:
• Single (one parent, one child)
Class
• Multi-level (child is created from another child)
Data type acting like blueprint for individual objects, attributes, and
• Multiple (many parents, one child)
methods. And rules for interacting with this entity
• Hierarchical (one parent, many children)
Objects • Hybrid (child extend several parents, where one or more of them is
Instances of class created with specifically defined data. Object has a combination of different types of inheritance)
a state (fields) and behavior (methods).
Methods Encapsulation (What happens in Vegas...)
Functions describing behaviors of object. By encapsulating a class's variables, only the methods of the class
can access them. It protects the data from external access or modifi‐
Attributes
cation.
Defined in class template and represent state of object. Object fields.
Polymorphism
Abstract Class | Interface
Subclasses can define their own behaviors and yet share some of
Abstract Class Interface
the same functionality of the parent class.
Describes Attributes, Methods
Compile time polymorphism -- Method overloading
methods
Class can have more than one method with the same name, but with
For classes With close That could have nothing in
different parameters
connections common
Run time polymorphism - Method overriding
(inheritance)
An instance method in a subclass with the same signature (name,
Multiple plus the number and the type of its parameters) and return type as
Inheritance an instance method in the superclass overrides the superclass's
Key words Implements Extends interface method.
interface
Extends class Abstraction
Methods (abstract And hiding the implementation details. Reduces the code's
without realis‐ keyword) complexity and makes it easier to use.
ation
Not only Inheritance
Methods with (default keyword)
realisation Composition “has-a” (strong connection)
Constructor Building has a room. Containing object owns it. Objects' lifecycles
are tied (if we destroy the owner object, its members also will be
Access any public (default), private
destroyed with it)
modifiers for methods with realisation
Aggregation “has-a” (medium connection)
Сar and its wheels. We can take off the wheels, and they'll still exist.
Doesn't involve owning. Lifecycles of the objects aren't tied: every
one of them can exist independently of each other.
Association objects “know” each other (weak connection)
SOLID principles
Single Responsibility
Class should have a single, well-defined responsibility and should not
be responsible for multiple things.
Open-Closed
Software enteties (classes, modules, functions) should be open for
extension but closed for modification. You should be able to add new
functionality to class without changing its existing code.
Liskov Substitution
Objects of a subclass should be able to be used in the same way as
objects of parent class without issues.
Interface Segregation
Classes shouldn’t have to implement interfaces that they don't need.
Dependency Inversion
High-level modules (i.e., classes depending on other classes) should
not depend on low-level modules. Both should depend on abstra‐
ctions. So, it's easier to change implementation of low-level module
without affecting high-level module.