Basic terms of object-oriented programming, table with comparison Abstract class and Interface in Java, SOLID principles, and Composition, Aggregation, Association.
|
Class
|
|
Data type acting like blueprint for individual objects, attributes, and methods. And rules for interacting with this entity
|
|
Objects
|
|
Instances of class created with specifically defined data. Object has a state (fields) and behavior (methods).
|
|
Methods
|
|
Functions describing behaviors of object.
|
|
Attributes
|
|
Defined in class template and represent state of object. Object fields.
|
|
Abstract Class
|
Interface
|
|
|
Describes
|
Attributes, methods
|
Methods
|
|
For classes
|
With close connections (inheritance)
|
That could have nothing in common
|
|
Multiple Inheritance
|
|
|
|
Key words
|
Implements interface
Extends class |
Extends interface
|
|
Attributes
|
|
|
|
Methods without realisation
|
(
abstract keyword) |
|
|
Methods with realisation
|
|
(
default keyword) |
|
Constructor
|
|
|
|
Access modifiers
|
any
|
public (default), private for methods with realisation |
|
Composition “has-a” (strong connection)
|
|
Building has a room. Containing object owns it. Objects' lifecycles are tied (if we destroy the owner object, its members also will be destroyed with it)
|
|
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)
|
|
Mother and child. The difference with aggregation is only logical: whether one of the objects is part of other or not.
|
|
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 abstractions. So, it's easier to change implementation of low-level module without affecting high-level module.
|
No comments yet.
Cheatography n. The art of mapping complex subjects into clear, instantly navigable reference guides.