Shohoj Token has been running at the upazila health complex for months, and now the director wants more. When the doctor calls the next patient, the waiting-room screen must change, an SMS must go to the person three places behind in the queue, and the doctor's own counter must update. Rahim, the programmer, does the obvious thing and writes all of it inside one method, callNext(). It works. Then the director asks for a voice announcement too, and Rahim opens callNext() for the fourth time that month.
Tania, a senior colleague, reads the method for ten seconds and says one sentence: "This is an Observer. The queue announces, and the screen, the SMS sender and the counter subscribe." Rahim has never met Tania's design before, yet he understands the whole plan at once, because that problem is old and somebody long ago gave the answer a name. Two words did the work of a half-hour whiteboard talk.
This chapter is about those names. A design pattern is a named, proven answer to a design problem that keeps coming back, and an architecture style is the same idea for the shape of a whole system. By the end you will be able to say what a pattern is and sort the 23 classic ones into their three families.
You will explain and draw the patterns exams ask most (Singleton, Factory Method, Adapter, Decorator, Composite, Facade, Strategy, Observer, Template Method) and name the rest with their purpose. You will choose between look-alike patterns, spot an anti-pattern and a code smell, and assign responsibilities with GRASP. Then you will describe software architecture, with its views, and compare the styles: layered, client-server, peer-to-peer, pipe and filter, repository, event-driven, broker, SOA and microservices, with MVC recalled in its place.