Skip to content

Try to cover major principle of OOP and common design pattern using python.

Notifications You must be signed in to change notification settings

GenesisBlock3301/deep_design_pattern

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Design Pattern

Before learning desing pattern we should take deep knowledge about Object Oriented Programming.

Major aspects of OOP

Encapsulation:

The key features of encapsulation:

  • An objects behavior is kept hidden from the outside world.
  • Client not directly change internal state acting on them rather client can send request to object. According to this request object change state such as set and get .
  • In python doesn't have public, private and protected keywords but accessibility can be made using __(double underscore) in the variable or function name.

Polymorphism:

The key features of polymorphism:

  • Two types of polymorphism:
    • An object provides different implementation of the method based on input parameters.
    • The same interface can be used by objects different types.
  • In python polymorphism build in feature.For example: + operator can add two or more integers and also concate string

Inheritance

The key features of inheritance:

  • Inheritance indicates that one class derives functionality from the parent class.
  • Inheritance is described as an option to reuses functionality of parent class.
  • Inheritance creates hierarchy via the relationships among objects of different classes.

Abstract

The key features of Abstruct:

  • It provides you simpe interface to the client , where the clients can interact with class objects and call methods defined in the interface.
  • Abstruct can create abstruct method as well as can implement method inside class but interface can't do that.

Composition

The key features of Composition:

  • It is way to combine objects or classes into more complex data structure or software implementation.
  • In composition, an object is used to call member functions in other modules thereby making base functionality available across modules without inheritance.
class A:
    def a1(self):
        print("a1")

class B:
    def b(self):
        print("b")
        A().a1()
obj = B()
obj.b()

Object Oriented Design Principles:

The Single responsibility principle:

Single responsibility principle states that a class should have only one reason to change.

If a class taking care of two functionality, it is better to split them.

The Open/Close principle:

The open/close principle state that classes or objects and methods are open for extension but close from modifications.

That means when we develop our software make sure that our writing classes or modules in a generic way. That's you can do extend behavior of class but not change to class itself.

For example: In Django user has to create a class implementation by extending the base abstract class to implement the required behavior insteat of changing the abstract class.

The inversion of control principle:

The inversion of control principle states that hight level modules shouldn't be depend on low level modules; they should both dependent on abstractions. Details should depend on abstractions and not the other way round.

This principle suggested that any two modules shouldn't be dependent on each other(loose coupling or decouple).

This priciciples also suggested that the details of your class should represent the abstractions.

The interface segregation principle:

This principle states that clients shouldn't be forced to depend on interface they don't use.

This principle suggestes that Develop mothods relevant to functionality. If there any method that is not related to the interface, the class dependent on the interface has to implement it unnecessary.

The substitute principle:

This principle states that derived classes must be able to completely substitute the base classes.

The concept of design pattern:

Advantage of design pattern:

  • They are reusable across multiple projects.
  • The architectural level problems can be solved.
  • They are time-tested and well-proven, which is the experience of developers and architects.
  • They have reability and dependence.

Classification of Patterns:

  • Creational Patterns
  • Structural Patterns
  • Behavioral Patterns

Creational Patterns:

  • They work on basis of how objects can be created.
  • They isolate the details of objects creations.
  • Code is independent of the type of object

Structural Patterns:

  • They design the structure of objects and classes so that they can compose to achieve larger results.
  • The focus is on simplifiying the structure and identifying the relationship between classes and objects.
  • They focus on class inheritance and composition.

About

Try to cover major principle of OOP and common design pattern using python.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published