-Before concluding this lesson, let's look at a few more patterns. And - -2
-although it will take too long to cover them in detail, I - -3
-would like to at least mention and quickly discuss a few more - -4
-of these more commonly-used patterns. In fact, some of the patterns that - -5
-I will discuss, you might have used yourself. Maybe without knowing their - -6
-name or the fact that they were design patterns. So let's start - -7
-with a Visitor pattern, which is a way of separating an algorithm - -8
-from an object structure on which it operates. And a practical result - -9
-of this separation is the ability to add the new operation - -10
-to exist in object structures, without modifying the structures. So, basically - -11
-what this pattern does, is to allow for defining and easily - -12
-modifying set of operations to perform on the objects of the collection. - -13
-And the typical usage of this is, for example, when you're - -14
-visiting a graph, or a set of objects, and you want - -15
-to perform some operations on these objects. By using a visitor - -16
-pattern, you can decouple the operation - -17
-from the objects. Although not straightforward, - -18
-this pattern is very, very useful. So, I really encourage you - -19
-to look at it in more detail and get familiar with it. - -20
-The second pattern I want to mention is the decorator pattern. - -21
-The decorator pattern is basically a wrapper that adds functionality to a - -22
-class. So the way in which it works, is that you - -23
-will take a class, you will build a class that basically wraps - -24
-this class. So it reproduces the functionality of the original class, but - -25
-it also adds some functionality. And for all the functionality that was - -26
-already in the original class, it will simply invoke this - -27
-functionality and for the new one, you will implement it - -28
-using the services of the class. And a nice property - -29
-of the decorator pattern is that it's stackable. So you can - -30
-add decorators on decorators on decorators, and further increase the - -31
-functionality provided by your class. The iterator is another very - -32
-commonly-used pattern. And, you probably use this one yourself because, - -33
-it's also part of many standard libraries. What the iterator allows - -34
-you to do, is basically to access elements of a collection - -35
-without knowing the underlying representation. So the iterator will allow you - -36
-to just go through a set of objects without worrying about - -37
-how the objects are stored. So you basically just ask the - -38
-iterator to give you the first object, the next object and - -39
-so on. Another very commonly-used pattern is the observer pattern. And - -40
-this pattern is very useful when you have an object of - -41
-interest and a set of other objects that are interested in - -42
-the changes that might occur in this first object. So - -43
-what the observer pattern allows you to do is to register - -44
-these objects, so that they let the system know that - -45
-they're interested in changes in this first object. And then, every - -46
-time that there is a change, these other objects will - -47
-be automatically notified. So basically, - -48
-the observer pattern allows for notifying - -49
-dependents when an object of interest changes. If you want - -50
-an example of this, just think about the file system and - -51
-imagine having a folder. All the views of this folder will - -52
-want to be notified every time that there's a change in - -53
-the folder because they need to refresh. So instead of continuously - -54
-checking the state of the folder, they will just register and basically - -55
-say, hey, we're interested in knowing when something changes in this - -56
-folder. And when something changes in the folder, they will be automatically - -57
-notified. So it will be some sort of a push notification - -58
-instead of a pull notification, if you are familiar with that terminology. - -59
-Finally the proxy pattern is a pattern in which a surrogate - -60
-controls access to an object. In other words, we have our object, - -61
-and we have our proxy here. So all the requests to the - -62
-object will go through the proxy that will then forward them. And - -63
-all the responses from the object will also go through the - -64
-proxy. They will then forward them to the original requester. So what - -65
-the proxy allows you to do is to control how this object, - -66
-that is behind the proxy, is actually accessed, for example, by filtering - -67
-some calls. So in a sense, the proxy allows use - -68
-for masking some of the functionality of the object that - -69
-is behind the proxy. And there's many, many, many more - -70
-useful patterns. That can help you when designing and implementing - -71
-the system. So once more, I really encourage you to - -72
-have a look at the book, to look at the - -73
-resources online, and to really get more familiar with these - -74
-patterns, and to try to use them in your everyday work. -- cgit 1.4.1