Design Patterns

#🧭DesignPatterns #💡OOP #💻SoftwareDevelopment

How do you measure the quality of the code? Can we consider that one way is looking into the collaboration among its objects? How do you decide on collaboration between objects when you plan your code? Focusing on these questions can lead you to come up with a simpler and understandablea architecture.

Why do we need Design Patterns?

We, software developers, need to communicate with each other about the coding solution that we are actively working on or planning to start. Considered that using a pattern name can save us on thousand word of explanation. Design patterns make our life easier, increase the collaboration while keeping the software development on track. On Gang of Four’s Design Pattern book there are four essential elements:

  1. The pattern name is a handle we can use to describe a design problem
  2. The problem describes when to apply the pattern
  3. The solution describes the elements that make up the design, their relationshipsm, responisbilities and collaborations.
  4. The consequences are the result and trade-offs of applying pattern.

“Inheritance”, “Encapsulation” and “Polymorphism” not explained in this book as a design pattern becuase programming languages used for problemsare not procedural languages. I am planning to create a post for these three and link to this blog.

How do we categorize Design Patterns?

Creational Patterns

  • Abstract Factory #Object
  • Builder #Object
  • Factory Method #Class
  • Prototype #Object
  • Singleton #Object

Structural Patterns

  • Adapter #Class and #Object
  • Bridge #Object
  • Composite #Object
  • Decorator #Object
  • Facade #Object
  • Flyweight #Object
  • Proxy #Object

Behavioral Patterns

  • Chain of Responsibility #Object
  • Command #Object
  • Interpreter #Class
  • Iterator #Object
  • Mediator #Object
  • Memento #Object
  • Observer #Object
  • State #Object
  • Strategy #Object
  • Template Method #Class
  • Visitor #Object

What is object granularity, how do you determine it?

Granularity is the size and the complexity of the object. It can vary from size, depth and number. Design patternsare are used for object granularity purpose too. Depending on the pattern you choose, object’s granularity also pre-defined and well structured in design patterns. Example by the Four Gang’s book, > The Facade Pattern describes how to represent complete system as objects, Flyweight pattern describes how to support huge numbers of objects at the finest granularities, Abstract Factory and Builder yields objects whose responsibility is creating other objects while other patterns describe specific way of decomposing an object into similar objects.

Written on February 21, 2022