Monday, August 8, 2022

Core Concept and Design Patterns

OOP core Concepts:

-Inheritance
-Encapsulation
-Polymorphism
-Data Abstraction


Abstract class: can't used directly, child class should inherit from abstract class and override the abstract methods.

Encapsulation means all the necessary data and methods are bind together and all the unnecessary details are hidden to the normal user. So Encapsulation is the process of binding data members and methods of a program together to do a specific job, without revealing unnecessary details.


Polymorphism (overload, override)
refers to the process by which some code, data, method, or object behaves differently under different circumstances or contexts.

For example, think of a base class called Animal that has a method called animalSound(). Derived classes of Animals could be Pigs, Cats, Dogs, Birds - And they also have their own implementation of an animal sound




How to prevent override? final keyword means I can't override this variable or method.



SOLID Principles for Clean Code:  are five principles of Object-Oriented class design
  1. The Single Responsibility Principle
  2. The Open-Closed Principle
  3. The Liskov Substitution Principle
  4. The Interface Segregation Principle
  5. The Dependency Inversion Principle



Single Responsibility Principle
a class should do one thing and therefore it should have only a single reason to change.

Open-Closed Principle
classes should be open for extension and closed to modification.

The Liskov Substitution Principle
subclasses should be substitutable for their base classes.

The Interface Segregation Principle
 many client-specific interfaces are better than one general-purpose interface. Clients should not be forced to implement a function they do no need.

The Dependency Inversion Principle
our classes should depend upon interfaces or abstract classes instead of concrete classes and functions.



Design Pattern



Factory Pattern

In Factory pattern, we create object without exposing the creation logic to the client and refer to newly created object using a common interface.











Strategy Pattern
 a class behavior or its algorithm can be changed at run time. This type of design pattern comes under behavior pattern.

In Strategy pattern, we create objects which represent various strategies and a context object whose behavior varies as per its strategy object. The strategy object changes the executing algorithm of the context object.









Cloud Design Patterns

























No comments: