Вопрос

I am new to pattern and it is a newbiew question. I started looking SOLID principle recently and also on design patterns. After going through over view of both, I was wondering if there is any way we can define relationship between SOLID and design pattern at one place. example..

S - Pattern a, Pattern B

O - Patten c, d, e

L

I

D

Like wise, I think it will help to understand the principle and pattern better.

Thanks Raj

Это было полезно?

Решение 2

The design patterns can't really be assigned to one letter of the SOLID acronym. Design patterns actually help you (or at least they are supposed to!) design your software in a way that respects all five points of the SOLID principles. The principles are some sort of guideline you should keep in mind while doing object-oriented programming even if you are not using a design pattern.

With that said, there are indeed categories for design patterns. For example, the gang of four patterns fell into the categories creational, structural and behavioral.

Другие советы

I see SOLID as the foundations for patterns. There are many examples. Take your favorite GoF design pattern, and break it down with SOLID. Not all principles may apply, but it's a great way to understand the pattern.

For example, the Strategy pattern has concrete strategies:

Strategy design pattern structure

Each concrete strategy applies the Single Responsibility Principle. The Strategy hierarchy is Open for extensibility, while the Strategy interface is Closed to modification (so the clients remain stable). Liskov principle applies within Strategies, but maybe it's not a great example. Interface segregation principle is demonstrated by the single Strategy interface (as opposed to some interface with lots of methods). Dependency inversion principle is not so obvious, in my opinion.

I think its a good relation to point : Open Closed Principle implies Strategy Pattern. Other than that Single Responsibility is applied in many of the design patterns . Dependency Injection is related to MVC design pattern. But there is not really very direct relationships between GOF and SOLID

Some of the GoF design patterns that help you implement OCP for example are template method (Through inheritance), Strategy or Decorator (Aggregation/Composition).

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top