0

What is the difference between design patterns and libraries?

I cannot seem to find the difference anywhere.

4

3 回答 3

1

DesingPatterns are considered to assist the developer by solveing already known problems. For instance, the ObserverPattern is used to observe a concreate object and carry out specific actions, the mediator is used to center the application logic and handle dependencies on a object, the composite is used to model a tree structure, etc. In general DesignPatterns can be categorized into three different types of patterns.

  1. creational
  2. behavioral
  3. structural

In contrast, a library is a complete different thing. It's a piece of generic source code that can be used by other applications.

于 2013-10-08T20:16:33.160 回答
0

A software library is a suite of data and programming code that is used to develop software programs and applications. It is designed to assist both the programmer and the programming language compiler in building and executing software - From Techopedia

A design pattern is a general reusable solution to a commonly occurring problem within a given context in software design

Apart from definition, Major difference from my experience:

When you are using a Library, you call APIs as per pre-defined fixed contract.

But when you are implementing a solution for a Design problem, you can solve the problem in one of the available design patterns OR multiple design patterns OR come up with your own design pattern.

Sometimes design patterns will try to limit your thinking in a particular way, which can be avoided. You can come up with your own pattern to solve the issue.

Even in current design patterns, a particular design problem can be solved with multiple design patterns. For some problems, you can implement the solution with either Strategy pattern or Decorator pattern. Some times, you can arrive at solution with combination of multiple design patterns.

Have a look at this article for better understanding.

于 2015-09-17T16:19:32.667 回答
0

A design pattern is a template you can use to build solutions. It is an idea, an abstraction, not a specific implementation. It is an explanation or a diagram. It is not code. Code is merely an example. A design pattern has unlimited examples.

A library is a concrete, pre-built, implemented solution. You can run it. It is code. Library code is generally designed to be shared among multiple applications.

Design patterns and libraries may overlap when a library implements one or more patterns; but this is not required.

于 2020-11-25T14:38:27.373 回答