Architectural vs Design Patterns: Software Engineering
Muhammad Asher Toqeer
Senior Java Developer | Backend | Spring | thebackendguy.com
Software design patterns are some proven ways to solve a reoccurring problem faced by programmers. These are general solutions to general problems which have been proven from the experience of many programmers. There are a lot of benefits using these patterns including more convenient solution, more cleaner code and since these patterns are now become standard, Its very helpful to use these pattern terms while explaining ideas to someone else.
Before directly diving into software design patterns, we must have to understand the difference between software architecture and software design since these terms are closely related and often cause confusion.
In general (switch off your inner programmer for some time) the architecture and design both explains the 'idea' but Architecture focus on the abstract view of idea while Design focus on the implementation view of idea. A design is much more detailed than architecture. Architecture pictures the abstract view of the whole system while Design pictures the implementation of some specific concerned domain.
Suppose government wants to build a new city. First they will create a high level abstract diagram explaining where will be the housing area, where will be factory area, where parks should be located, where to locate grid systems, hospitals, schools, markets and so on. This is Architecture. Now after that they will create diagrams explaining how houses are built, how much maximum area a single house can have. How to build houses side by side. How much wider the school front would be. How many beds and rooms the hospital would have, etc etc. This is Design.
Now come back to programming, an Architecture explains components and their interaction while a design explains how each component is built or would be build. So there are architecture patterns and there are design patterns and both of them are different.
Architectural Patterns:
There are bunch of architectural patterns available and choice of one is solely depends on the nature of the given problem. Some famous patterns are:
- Model View Controller
- Model View Controller Service
- Model View Presenter
- Model View ViewModel
- Multi tier
- Micro services
- Event Driven
- Service Oriented
and much more...
Design Patterns:
There are famous 26 design patterns divided into three categories:
1- Creational Patterns:
Includes Abstract Factory, Builder, Factory Method, Object Pool, Prototype and Singleton pattern.
2- Structural Patterns:
Includes Adapter, Bridge, Composite, Decorator, Facade, Flyweight, Private Class Data and Proxy pattern.
3- Behavioral Patterns:
Includes Chain of responsibility, Command, Interpreter, Iterator, Mediator, Memento, Null Object, Observer, State, Strategy, Template method and Visitor pattern.
How to use these patterns?
The choice of relevant pattern depends upon problem and choosing right one requires experience. These patterns can be used in any field of computer science, from simple applications to AI based solutions, from Games to Business Intelligence, from embed systems to websites.
Although these patterns are very helpful, yet you have to be careful because choosing wrong one will actually makes your program a mess. Never try "must use this pattern" instead you should always think about your problem first and then think which pattern should be appropriate. There are no hard and fast rules about implementation so you can customized solution according to your need. These patterns should obey your program, not vice versa.
That is all for today, In later articles we would discuss these patterns one by one with very simple and understandable examples. Thanks for reading, please leave a comment in any case of question or suggestion. Happy coding !
Senior Software Engineer | Python | Node | Docker | AWS
5 年Good Article
System Engineer / Solutions Architect
6 年Great explanation, Thanks