Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

What is the difference between Object Oriented Design Patterns and Principles? Are they different things? As far as I understood both of them try to achieve some common goal (e,g. flexibility). So can I say a pattern is a principle and vice versa?

Design Principle = SOLID (i.e. Dependency Inversion Principle)

Design Pattern = Gof (i.e. Abstract Factory Pattern)

share|improve this question

migrated from stackoverflow.com Jun 20 '12 at 11:38

This question came from our site for professional and enthusiast programmers.

7 Answers 7

up vote 17 down vote accepted

No, they aren't the same.

Patterns are common solutions to object-oriented programming problems. (I'm not aware of any similar books for functional or declarative programming.) The idea was crystallized in the famous "Design Patterns" book by the Gang of Four in 1995.

As Andre points out, patterns are common in every paradigm. I'll reiterate my previous statement: I'm not aware of any similar books for functional or declarative programming, but Andre has remedied my ignorance with the link he provided below. (Thank you, Andre.)

Principles are less about particular languages or paradigms, more general. "Don't Repeat Yourself" - DRY principle - is true for all programming.

share|improve this answer
3  
Patterns exist in every paradigm. Jeremy Gibbons is writing a book called Patterns in Functional Programming (and blogging about it here). Patterns are just what the name says - recurring designs, that solve similar problems. They're everywhere, 'though you may not always recognize them. –  André Paramés Jun 20 '12 at 12:26
    
@AndréParamés A quick skim through leads me to believe Jeremy Gibbons is talking about language idioms, not design patterns. –  Izkata Jun 20 '12 at 15:32
    
@Izkata Non-OOP Design Patterns? –  Roc Martí Jun 21 '12 at 11:49

These concepts are not same :

*Design Principle : * Software design principles represent a set of guidelines that help us to avoid having a bad design. like: Open Close Principle

*Design Pattern : * a Design Pattern is a general reusable solution to a commonly occurring problem within a given context in software design. Like: Singleton

share|improve this answer

Patterns are to principles, what implementations are to patterns.

A principle would be "indirection", which could be accomplished by a "factory" pattern, which gets implemented as a class with factory methods in the end.

share|improve this answer

Well, Principles are rules while patterns are their concrete examples.

share|improve this answer
1  
can you give some examples? –  Chandi Gorom Jun 20 '12 at 10:23
    
Please tell us the principle that calls for Factory or Chain of Responsibility or Flyweight. –  duffymo Jun 20 '12 at 16:11
2  
@duffymo Well Factory for example follows Dependency Inversion Principle (not injection); both the client and the instance depend upon the abstraction - the interface. Chain of Responsibility is based on the principles of loose coupling and separation of controlos. Flyweight I believe has only performance gains. –  m3th0dman Nov 7 '12 at 21:25

Patterns are more high-level things, than principles. Patterns resolve specific issues. Principles could be applied anywhere regardless of context. Actually patterns based on principles (SRP, DRY, etc)

E.G. Lets look on Strategy pattern. It defines a family of algorithms, encapsulates each one, and makes them interchangeable. So, you have here high-level concept of algorithm. With State pattern you have high-level concept of state. With principles you don't have any high-level concepts. Principles are building blocks, which used by patters to achieve goal. When you implement Strategy pattern, you use SOLID:

  • SRP - you define code, which responsible for algorithm and extract it from another code.
  • OCP - you define abstraction, which represents all different algorithms and use it
  • LSP - you don't use concrete algorithm classes in client code, only abstraction
share|improve this answer
3  
Actually patterns are of a lower level than principles. That is to say, that a pattern is closer to the actual implementation than a principle in this context. In other words, principles are more abstract than patterns with principles meaning general design guidelines and patterns representing solutions suitable for a particular class of problems. –  Jarkko Jun 20 '12 at 10:07
    
@Jarkko see my example. When I talked about level, I meant that patterns are based on principles, not vice versa. Brick is not more high-level thing, than building. –  lazyberezovsky Jun 20 '12 at 10:14
3  
I can see what you meant by that and understand your thinking on the matter. It is, however, contrary to the common meaning of the concepts "high level" and "low level" in the context of software. (For some reason i can not @-tag you.) –  Jarkko Jun 20 '12 at 10:19

Patterns where originally documented for Architecture. In architecture, apply to things ranging from placement of the door in a room to the layout of a village.

The Gang of Four applied the idea to Object-Oriented Programming. There may be more than one pattern which can be used to solve a problem, but each pattern will have a specific implementation. Patterns exist in other programming approaches, but I am not aware of any applicable books. As others have mentioned Patterns cover specific implementations. Using a pattern when it doesn't apply is often considered an anti-pattern.

Principles don't cover implementation, although there can be standard implementation approaches. Principles are more about covering general issues rather than specific problems. For Inversion of Control, I am aware of at least three implementation approaches. For DRY (Don't Repeat Yourself) I don't know of a singe specific implementation approach, although I use several.

Consider

  • You have been requested to a Pattern like Abstract Factory Pattern as the only approach to develop a program. Would this be appropriate? No, then it is more likely a Pattern.
  • You have been requested to use DRY only to develop object creation components? Would this be appropriate? No, then it is more likely to be a Principle.
share|improve this answer

OO Design Principle—

OO principle is a set of guidelines that ensures OOP concept. Based on the OOP concept, this defines ways to design better way, a better design. The basic OO design principle is SOLID.

A Design pattern provides a general solution to a design problem. Please note “design pattern” can be applied to noon object oriented word too. So A OO design patterns (OODPs) are those which provide a general solution to object oriented design based OO principle. Design patterns are discovered, not invented. There are several ways to define OODPs and most famous one is BSC [Behavioral Structural Creational].

Following is the link for detailed explanation. http://techythought.wordpress.com/2013/01/21/design-principle-vs-ds-design-pattern-describing-oop-elements/

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.