Communiquez avec les autres et partagez vos connaissances professionnelles

Inscrivez-vous ou connectez-vous pour rejoindre votre communauté professionnelle.

Suivre

What are design patterns? Have you used any design pattern in your code?

Tell us about one design pattern you have used before.

user-image
Question ajoutée par Mohammad Ateieh , Software Engineering Manager , Bayt.com
Date de publication: 2013/08/26
Umar Alharaky
par Umar Alharaky , Senior Systems Analyst & Quality Control , StarWays IT

Design patterns are recurring solutions to software design problems you find again and again in real-world application development.
Using of design patterns shouldn't decided during code writing.
The decision of using such design pattern should be taken during building the architecture & detailed design of the required system.
I used to consider Singleton design pattern when I want to ensure that a specific class has only one instance and provide a global point of access to it.
For example, the PrintSpooler class and LoadBalancer class are typical examples for singleton.

Nur-Ahmad Furlong
par Nur-Ahmad Furlong , UX / UI Lead - Design Manager , Softhouse.io

I like the way Umar Alharaky referred to it as recurring solutions. Design Patterns apply to just about any problem area and could be based on coding, visual design, building and other problem/solution processes.

Typically after some time certain design patterns settle as the norm for solving a specific type of problem within a given set of circumstances, until of course the conditions or environment changes.

 

I believe a certain amount of this also follows development trends and some patterns are merely trends which die down. Other design patterns are so fundamentally apt that they stick and almost never change in the fundamental ability to solve a given problem.

Utilisateur supprimé
par Utilisateur supprimé

Design patterns are architectural and code templates for how to solve a problem that can be used in similar situations. It's about reusability. Instead of re-inventing the wheel, you can apply a general design that addresses a recurring design problem. It describes the problem, the solution, when to apply the solution, and its consequences.

There are several famous ones such as MVVM, MVC, Producer-Consumer, Factory, Singleton, Facade, Decorator, Adapter, Iterator, Proxy, Composite, Abstract, Bridge, Builder, Prototype, Observer, State and State Machine, Visitor.

In fact, we use them on a daily basis even if we are not aware of it. They can be used alone or in combination. But they are not the ultimate universal solution to all kinds of problems.

Sometimes a generic implementation can lead to a lot of overhead which may lead to an inefficient solution.

For example, it would be better to use a for loop instead of using an enumerator for single dimension arrays because it'll be much faster.

Also a better way to create an instance of a type is by using DynamicMethod rather than using Activator.CreateInstance. etc.

Rashid Anwar
par Rashid Anwar , senior php developer , sparx it solution pvt ltd.

In simple words design pattern specifies how the objects in an application are structured and related to each other. i.e dictates the arrangement of objects in a particular context. there are many design patterns available each suitable for unique and different kind of problem. singleton pattern is best used for db deriver class when only one instance for db connection required. strategy pattern helps us to make decision which class need to be instantiated depending on the context. factory pattern, as the name suggested a class designated as factory to deliver various king of objects...

More Questions Like This