본문 바로가기

Mastering Python Design Patterns15

The Observer Pattern in Reactive Programming The Observer Pattern in Reactive Programming In the previous chapter, we covered the last four in our list of behavioral patterns. That chapter also marked the end of the list of patterns presented by the Gang of Four in their book. Among the patterns we have discussed so far, one is particularly interesting now, for this new chapter: the Observer pattern (covered in Chapter 11, *The Observer Pa.. 2023. 3. 22.
Other Behavioral Patterns Other Behavioral Patterns We have seen in Chapter 12, *The State pattern, which helps us in making behavior changes when an object's internal state changes, by using state machines. There is a number of behavioral patterns and, in this chapter, we are going to discuss five more of them: Interpreter, Strategy, Memento, Iterator, and Template. What is the Interpreter pattern? The Interpreter p.. 2023. 3. 22.
The State Pattern The State Pattern In the previous chapter, we covered the Observer pattern, which is useful in a program to notify other objects when the state of a given object changes. Let's continue discovering those patterns proposed by the Gang of Four. Object-oriented programming (OOP) focuses on maintaining the states of objects that interact with each other. A very handy tool to model state transiti.. 2023. 3. 22.
The Observer Pattern The Observer Pattern When we need to update a group of objects when the state of another object changes, a popular solution is offered by the Model-View-Controller (MVC) pattern. Assume that we are using the data of the same model in two views, for instance in a pie chart and in a spreadsheet. Whenever the model is modified, both the views need to be updated. That's the role of the Observer .. 2023. 3. 22.
The Command Pattern The Command Pattern Most applications nowadays have an undo operation. It is hard to imagine, but undo did not exist in any software for many years. Undo was introduced in 1974 (j.mp/wiundo), but Fortran and Lisp, two programming languages that are still widely used, were created in 1957 and 1958, respectively (j.mp/proghist)! I wouldn't like to have been an application user during those yea.. 2023. 3. 22.
The Chain of Responsibility 9 The Chain of Responsibility Pattern When developing an application, most of the time we know which method should satisfy a particular request in advance. However, this is not always the case. For example, think of any broadcast computer network, such as the original Ethernet implementation (j.mp/wikishared). In broadcast computer networks, all requests are sent to all nodes (broadcast domains .. 2023. 3. 22.
Other Structural Patterns 8 Other Structural Patterns Besides the patterns covered in previous chapters, there are other structural patterns we can cover: flyweight, model-view-controller* (MVC), and proxy. What is the flyweight pattern? Object-oriented systems can face performance issues due to the overhead of object creation. Performance issues usually appear in embedded systems with limited resources, such as smartpho.. 2023. 3. 22.
The Facade Pattern 7 The Facade Pattern In the previous chapter, we covered a third structural pattern, the bridge pattern, which helps to define an abstraction and its implementation in a decoupled way, so that both can vary independently. As systems evolve, they can get very complex. It is not unusual to end up with a very large (and sometimes confusing) collection of classes and interactions. In many cases, we .. 2023. 3. 22.
The Bridge Pattern 6 The Bridge Pattern In the previous two chapters, we covered our first structural pattern, adapter, which is used to make two incompatible interfaces compatible, and decorator, which allows us to add responsibilities to an object in a dynamic way. There are more similar patterns. Let's continue with the series! A third structural pattern to look at is the bridge pattern. We can actually com.. 2023. 3. 22.