Design Patterns Review
Transcript
Welcome to design patterns. Today's the last lecture in design patterns. I see there are many more participants than normally. Perfect. Because today we will talk about the content of the whole lecture. So what did we talk the last few months? And afterwards we will do a practice exam together where we can try the exam setting. I have not activated the exam in teach center right now. I will do this after the summary okay.
So first I will give you a short summary of the whole lecture, then we'll do the practice exam. And in the end I ask you to please do the evolution of the course. So give me a final feedback and then official feedback what we should keep for next year, what should change for the next years? And any other comment you have in the end? There is some optional task because the Institute for software technology asked me to give you a crease on software box. This is from a project of them.
And there you have to evaluate the type of software park back report. So has this something to do with memory has this something to do with configuration management and so on? They use this in a research project of them. And yeah. So if you're interested, the link is in the teach center and I will also post it here in the big blue partner room in the chat. So yeah, if you're interested in We send software packs and software reports. Then please help the Institute for tufted technology and do this quiz in the end. But this has nothing to do with this lecture. This is just a cooperation between the institutes.
Okay. In the first lecture I asked you, which design patterns do you already know? This was the vert cloud, which yeah, you created. And if you look at it, you already knew many patterns before. And the funny thing is now, in the meantime you all know these patterns. So not only singing persons, but actually if you look at the vert cloud, you should know each and every pattern which is on there, maybe there is a pattern which we did not do in the lecture.
I think God class is an anti-pattern and we model, yes. So this was not in the lecture. But most of them we covered, which is a cool thing. If you think half a year ago, you didn't know all these patterns now, you know, it. Okay. From the timeline. So for the big picture, we covered a huge amount of patterns. We talked about each and every one of them or To be more specific. V I provided you some videos, some lecture videos about it. You watched them. And afterwards we, in the first few lectures, we did some live programming, which didn't work out that well. But afterwards, we switched over to doing this interactive quiz using feedback, which, which worked way better and many questions in the
feedback, a quiz we also discussed. So there are some unclear things, divert some questions, and I try to answer all of them. Today, as you can see, we are in the last lecture and here, we only will see your summary and the practice exam to be prepared for next week. First of all who in, who starts did the whole pattern movement? It was Christopher Alexander, not in 2012, but in 1977, by writing his book about architecture, which is called a pattern language. And there, he set the foundation, the building blocks of all patterns, missing a pet, a needs, a context. A pattern needs a description of the problem and the forces and the pattern needs the solution. And what is the most important part? The consequences for that pattern.
You also have to describe the benefits and drawbacks of each and every pattern, because this is the experience. This is the insight and knowledge. So he started it for the architecture domain. And then these, this movement switched over to software development and software architecture. Okay. The most famous book of course, was the design patterns, elements of reusable object oriented software, that book by the gang of four, Ralph Johnson, Eric gamma, Richard helm, and John Vlissides, which we can see on the, on this slide here.
So they all brought the pattern movements to the software domain. And then a huge movement started in, in, in Europe, in America, on the whole. World and many other books came out. For example, the whole series of patent oriented software architecture books, the poser books. There are so many other serious, but these were the books we covered in the lecture. All the patterns which we have seen in the lectures come from the gang of four book and out of these four.
Books which collected patterns from different authors and different pattern conferences and yeah, summarized it in their books. We have seen many videos by Douglas Schmidt, which is also one of the author. I mean, you look at poster four, for example, or poser to Dr. Schmidt was one of the main office in these books. So he's not the inventor. But he collected all those patterns and the wrote it down. So it's cool that he also makes some pet on videos that we have one of the original authors in the lecture.
This is an overview of all the patterns research we have seen in the lecture. And of course you don't have to know all of this stuff. So this is a quite overwhelming amount. These are actually the names of the patterns, which recovered. I will not read all of them, but. I will go over some of them just to give a refresher, which patterns we covered in the lecture for each of these patterns, there is a huge catalog in the teach center, which you can click on and then you come through the, to a page where all the videos are linked all the lecture videos.
So if you search for a specific pattern, just search it in the teach center, in the glossary. So we have in teach center on the first, on the first yup. Part on the first option that we have. The firstly, the slides, secondly, the glossary and in the glossary, all patent videos are linked. All the pet videos are also linked in tube. The TU Graz video sharing platform, but only the Vidos I produced. I did not upload the other videos there because as you know, I also
used many other lecture material, for example, by Douglas Schmidt and so on and I am not allowed to upload it to our TU Graz Tube, but let's continue by going over the patterns, which we covered first, we talked about some wrapping patterns, which is the very most general form of a pattern. So if it cant solve a problem, just wrap around another layer of abstraction and try to solve it. So here very famous patterns are like the adapter, the proxy, the decorator, and the facade.
Then we talked about creational patterns. Really the main purpose is to create objects. And sometimes the creation process is more complicated. Sometimes it has smarter steps. For example, the builder has multiple steps to create a project, an object, or think of the prototype, which is like a template where you can create objects at runtime or classes at runtime. If you want.
The single can, which allows only one instance. So here, the creation is also taken away from the application developer. The single can takes care of that and only created once. And it guarantees that you only have one instance and so on, then we have some behavioral patterns. So what are behavioral patterns? So they change or the implement the behavior of objects. So here we have strategy where you want an algorithm but in an abstract form. So you only want to use some method.
You don't want to implement it yourself, or maybe you want to exchange the methods during run time. You just stretch. She comes in very handy also to command very kin Peck a method. And it's its environment into one object and store it somewhere, call it later, maybe, or undo it and so on. So this is all things of the command and the state pattern, which is also a behavioral pattern. This is very often mixed with Other patterns . So the state actually is about changing the behavior of an object in this case state machine. So if you see an object as a state machine and depending on which state it is, it should do different actions and different. Yeah. And react in different ways. Then the stain pattern is to correct one. So this is the perfect pattern for a state machine.
Then we talked about architectural patterns, of course, layers broke a master slave client server, but also pipes and filters then patterns, which work well with collections like the iterator. This was actually first patent, which we talked about in the lecture, the iterate. And of course, most of you knew it before, but now you also know that the pet and form of it. And also that iterator is implemented differently in many languages. So every language decides for itself how exactly the iterator is implemented.
Then we talked about communication patterns. So patterns, which sent information to other objects, which decouple a sender and the receiver, which encapsulates some data or information in a message and sent this S a letter over the network, for example. And what else do we have here?
Model view controller we have here. So this was in the last week's lecture, which is Maybe this should be moved to two behavioral patterns because model, if your controller is more about splitting up the responsibilities of objects, not so much about communication, but of course this has to do with communication. So who communicates with whom should all objects communicate with every other object? Or should we define some data flow and control flow between these different roles of model, view and controller?
Okay, so next concurrency patterns. Of course, we talked about locks, the monitor active object, which is a very cool pattern, versatile pattern. The future scoped locking Anton async await was also part of the lecture. And what next resource patterns, which are all about when should I acquire my resources and how can I avoid forgetting the release of resources, for example, using garbage collector using leasing, but also the the scoped resource was also part of this. I forgot it. In this list. I will update the slides. These slides will also be uploaded into teach center and I have to write it down. I forgot scope the resources, but I will update this, after today's lecture, And then we had some patterns
which do not belong in, into a specific group, but are also very important to know, for example, to memento or the counted point or outer point or smart point or call it whatever you want. But the idea behind is interesting so that you. Take away the burden of manually releasing an object, but you count the references or hold it a memory until no, nobody needs it anymore. And then you delete it.
Then the chain of responsibility, the interpreter. And of course, with the interpreter also to obstruct syntax three, they belong very well together. Wow, quite an number of patterns. With that, one of the things which is important is also by just knowing the name and the basic idea. You can talk to other developers, you can talk to other students and say, okay, let's use a monitor there, or let's use the command pattern there. If you have a specific problem and this makes communication way easier.
And this brings me to the learning goals of the lecture. So in the beginning, in the first lecture, I also showed you what the learning goals for this lecture. And let me repeat them and let's see how we did. So the first design patterns theory, what is the design pattern and why do we need it? Then what are the core principles, the solid principles, for example, then how to describe a design pattern. For example, 37 pattern house.
I will cover some of these questions in the latest slides, but let me just go through it then. What is the whole pattern language? Why do we need a pattern language? The next. Then we talked about around 50 design patterns in detail. So what are the benefits to throwbacks? What is the context? Some patterns we talked about in more detail than in others. So for some patterns, we only got the idea, the basic idea, and maybe the application of it and regarding the application also, it is important to know when should you use what. So he's the broker, which is a wonderful and versatile communication pattern. Should we use the broker everywhere
and in all our applications? Of course, not only very, it makes sense. And we've discussed some of the use cases where it makes sense. Okay. So the actual learning goals was, you know, common design patterns and the core. Yeah. You can apply them in software development, regardless of the programming language. This is an important thing. Software design patterns should be, should not be bound to a specific language. This is, these are called idioms, not idiots, but ATM's, which are specific who, a programming language, but software design patterns in the more channel. Notion should be independent of the language.
Then you can derive the consequences of design patterns and see, or evaluate your design decisions. For example, should we use a mediator pattern or should we use the observer pattern for the specific use case? You should see what the differences are and which is more appropriate. You decide if the consequences are of a pattern are acceptable or not, you avoid over-engineering and misuse of patterns.
This is, I think I mentioned this quite often that you should not use a design patterns for a hello world application or for a simple script. It doesn't make any sense, but for an any bigger project, it makes sense to use more and more design patterns . Because they make your architecture more flexible. They avoid common problems and so on, and you don't have to reinvent the wheel. And then the last learning goal was you can make reasonable design decisions by balancing out forces consequences for a specific set of requirements and problems.
So what is the design pattern? This is a question which is in all exams. And my short definition was a proven solution for a recurring problem. You could also say a solution template for a problem which occurs very often or simply a template for a problem. I also accept creative answers to this question, but the important thing is that it solves a problem which occurs over and over again. And that it dis it is proven. So it's also a similar solution, which solves this problem in multiple projects.
So you have used it multiple times already and it's proven, and actually it is not a concrete solution. So you just gave, give away the idea behind how to solve this problem. A solution idea would also be a valid answer, but a solution at the year, which was implemented multiple times and solves a problem, then it's correct. Just solution idea is not enough.
So design patterns consists of several parts, which sometimes I call differently, but basically the name is important. So we want to have a catchy name for a pattern, not the whole sentence, which describes the patent, but a catchy name, like adapter, like broker, like active object. Then we want to know the context, very easy to applicable because patterns can exist in software development. They can exist in, in hardware development in there are social patterns. There are patterns in architecture near nearly in every domain. There are patterns most to lose someone.
So you have to describe in which context, this pattern applies. You can not apply a software development pattern for for mountain camping. This are different contexts for us in the lecture. Of course, mostly the context is you are developing a software and yeah. Some problem workers there. So the problem. Also must be in the description of a pattern. What do we want to solve? The problem should not be trivial because then it's clear and obvious what to do. So the problem should be a complicated situation, which is not obvious.
And when is a problem difficult when it has antagonistic forces, conflicting forces. So some pulling forces some PR pushing forces, and this physically Mustapha stands for you have constraints in your software. So why is the problem difficult lie? Does it hurt? In this context. Very often, for example, if your context is embedded development and you want to apply a pattern very often, you don't have enough memory. You only have limited CPU resources or very low or very low energy. Requirements and so on. So this has some constraints and this constraints often force you to go in this specific direction of if your solution, because nothing else would be feasible or reasonable.
And this leads me to the solution itself. So here you should provide a generic description of the pattern. Very often, this is given in two parts. So what are the static participants? So what are the objects and classes, which work together and the dynamic part. How do they work together during runtime? How they are build up? Who communicates with whom and who calls whom in the end? After applying the solution, we have a resulting situation and this is called the consequences or rationale behind the pattern. So what are the benefits and liabilities of this resulting situation? For example via using a broker, but Oh, suddenly we have so many VF communication overhead, and we have to use Marta paper processes or Marta for machines
where these brokers should run on, the client should run on the servant. I don't notice that anymore. I have to register it first and so on. So there are some liabilities we have to think of after applying patterns. Okay. Also, what are the limitations, for example, using the observer, is a cool pattern, but if we, if he call it synchronously and 10 million objects observed for a single a data change, and we all have to inf you have to inform all these objects around time, our application will get very slow.
These are some trade-offs. And then the known users. So how is this pattern applied in real life? These are actual solutions. These are implementations in real life and yeah, most of the time for us, especially since most of you are already in the master have seen already many examples and we. Included many examples in the videos and the lecture, but not for every pattern. I have to admit this if not shown this for every pet.
Oh okay. So here, I want to repeat the pet and house metaphor again so that you remember the parts of a pattern. So above all the name. The name of the pet understands. And the roof resembles the context of the pattern in the inside. We have a problem and the forces and corresponding to that dissolution and the consequences. And you can see these are all connected to each other.
So the solution solves the problem is this the right direction? Am I mirrored or not add? Doesn't matter. The solution solves the problem; the problem induces, or is difficult due to the forces. And depending upon the solution, we have some consequences which solved the forces in one way or the other, for example, we could decide for A very lightweight implementation, which does not provide so much flexibility. It's a full fledged yeah, for example, layers architecture, but it runs on our small devices, for example, on their light bulb, in automotive systems and so on. So this is always some design decision you have to make.
And. Everything stands upon the known users, which are the basis of all patterns . So a patent and most alerts only becomes a pattern when it's applied over and over again. And then you see, Oh, this actually works. Therefore the known users are okay. So then there are principles behind the patterns. So these principles were already known before the pattern movement, but actually it has been found out that every pattern is guided by these principles and the solid principles are, for example Very important. For example, the S stands for single responsibility. A class should only have one responsibility and therefore only one reason to change it, then they open closed. So you should implement the class behavior and you should be able to
extend this behavior without modifying the source code of the class. The disk can very easily be achieved by using the strategy or the state pattern, for example. So the original state machine is unchanged. The source code of the state machine is unchanged, but by providing it with a configuration of the state machine of their transitions and of the States, you can modify that behavior of distinct machine.
Then this cough substitution, which is yeah for free, if you use modern programming languages, that you should be able to substitute derived classes instead of their base classes, then it can make some interfaces. You can make abstract classes and you can use these interfaces and abstract classes, but actually you're using the instance of a derived. Object of a child object of that, then interface, segregation that you make fine-grained interfaces, which are specific to a client. So you should not give the client all possibilities. You should restrict the possibilities to exactly what he or she needs.
There also the idea of make an interface hard to use, easy to use, right, and hard to use wrong. And the last is dependency inversion, which is of course a similar idea to list crop substitution, but here more on the implementation side. So you should not use concrete classes. You should use abstractions, for example, interfaces or abstract yeses. And this makes it easy to derive from this extra classes or implement interfaces and allows the older using developer to provide his or her own implementation.
Okay. What else? I see. We should. Make it a little bit faster because actually everything I say now is, was also already said in the first lecture, and there's also a video of this online, so a to repeat it, to bring it back into your minds. We also had this principles of good programming, like decomposition, abstraction decoupling and usability and simplicity. So decomposition is a very egg rhythmic approach to break down a big problem, which you are unable to solve into smaller steps and try to solve the smallest steps.
This can be, I didn't lie also. So if you want to have to write your master thesis or dissertation or bachelor thesis, and you stand in front of this huge mountain of work, you have to break it down into chapters. You have to break it down into single tasks and solve these tasks one after another and go step by step, and then you can solve the whole problem. This is the idea of decomposition. Then abstraction, if something is too complicated, then rep a simpler layer around it, like the adapter or a proxy, or the latest pattern also uses this kind of idea and obstruct a way to details.
If you want to continue communicate this or send a message over the internet, do you want to know exactly how the Mac frame is built up or, what are parts of the IP header? No, as an application developer, you just want to send a message. Abstract away the details, and then you can handle it more easily than decoupling and decoupling means to shift the decision times to later, basically to not directly know the communication partner for example, but combined this at runtime.
Introduce dependencies. So you should not be that you have to recompile your complete source code whenever you're making a small change anywhere. It should be that these objects are decoupled from each other. And of course, by using interfaces and by using extra classes and the header files you can make. This work by using abstractions and programming against obstructions, you can decouple objects from each other.
Okay. And in the end, usability and simplicity here again, we have this famous saying basket Myers, make things easy to use right and to hard to use wrong. Provide an easy interface to the application developer, adhere to the expectations and make the usage of your classes intuitive. And with this also avoid over optimization or premature optimization, just implement what is needed right now.
Of course you should think a little bit ahead, but not too far. Otherwise you're over engineer solution. And with adhere to it, expectations is meant Very often programming languages have their coding standards, have their styles, which you use. And if you switch between languages, you're tempted to, to use your own style, which you'll know already and apply to a different language. And this is very often completely chaotic and others cannot read your code or do not understand it intuitively. So try to adhere to the context, which very you are working on also regarding your IDE, for example, used
to add a U, which is used in your company and do not force everyone to use way more Emacs or whatever. Of course they are good editors and good. Programming environments, but if your company using is using visual studio, then please also use weave studio. Don't be so forced or don't be so narrow-minded okay.
Some different types of design patterns and this It's an artificial structure, as I already mentioned, but there are patterns which have, which influenced the whole architecture of your software. For example, the layers, the broker model view controller, although there is some controversy about this, but, these design patterns influence the whole software application and the whole architecture of your application. And therefore they're called architectural patterns. Then.
There are classical design patterns, which influence a few components, but not the whole architecture. And also more than just a single method because singly methods, design patterns, or design patterns, which are specific to a language are called idioms. So they solve very small problems. For example, the counterpoint as COVID blockings coped resources, these are idioms, or for example, the boiler plate in Python. So the, if name equals main, then this is also an EDM specific to Python. Python.
Okay. Okay. Here we have an overview of the gang of four design patterns and I marked in green, actually, they should have Being, they should face in one after another, but doesn't matter. I marked in green, all design patterns, which recovered. And as we can see, Hey, we covered the whole book, perfectly recovered, decorator recovered composite iterate my mentor and so on and so forth. Perfect. You know, the whole book now next, we also covered many patterns of the puzzle. One book.
For example, Mazda slave proxy, Blackboard command, or command processor as it was called in the book. Then model view, controller presentation, obstruction control, hold part. This is the composite pattern. It was just called whole part in the book. But actually this is just an alternative name for the composite pattern counted pointer. And so on.
We neglected some, for example, the reflection pattern. We did not cover the few handler, the, for what our receiver, we did not cover, but. Yeah, maybe their reflection would have been interesting, but as you can already imagine, I think most of you noted the core idea that you can find out may tie information about objects during run time. So reflection is about storing which methods do that's my, does my object have, or my class, which attributes, and that I can find about this at run time.
Okay, then the pose, a two book also has a pattern language overview, and we can also see, be covered most of the design patterns except for some which I deemed not that interesting. And which we did not have time in the whole lecture, for example, half, half sink, half async an object, which you can call synchronously and asynchronously and which synchronizes itself between the two worlds.
Or the extension interface. We also did not cover, which you said about if I want to have a simple interface, I call effector methods, which returns me a simple interface. If I want to have an advanced configuration possibility, then I call a factor, a method which returns me the same object, but under a different interface and supplying more possibilities. So here I can choose which complexity with which complexity I want to have, or I want to handle an object and so on.
So as you can see also recovered most of the patterns here. The other poses books did not have such a convenient overview. So I did not include it here in the slides. Okay. In the end, a few philosophers thoughts, patterns of the universe. You see it in the picture. So patterns are actually a universal principle. Maybe evolution works with patterns. Survival of the fittest works with patterns, but applied to the knowledge domain. How do we transfer knowledge? So what is knowledge? Do we just learn anything by heart and repeat it? And when do we apply ideas? So we have to have an inner model in our brains, which decides if we can accept some consequences or if we can not accept concepts and patterns are one way how to express this model.
So first we want to make knowledge explicit by writing it down. We want it to be find-able by publishing it in books, in papers, in conferences, in videos. We want to make this knowledge understandable. Oops sorry. I got to just go there. And message here. Okay. We want to make it understandable by writing it down in his structure, which we are used to in which we can read and understand.
And in the end we want to make it applicable. So did you not only learn something by heart, but also know how to apply it. How to use it in a real world in a real problem, because this is the most important part, actually. Okay. That's all regarding to summary. I thank you for participating in the whole lecture. That's all folks.
And now we switch over. Oh. Uh, there's a famous quote. I want to tell you, in the end, by Richard Feynman, one of my, one of my idols. Study hard what interests you the most in the most undisciplined, irreverent and original manner possible. And what you meant was don't just go the way which some lecturer or professor tells you go your own way and try it in your own problems and apply it to your own context in your own projects. And that's how you learn the best.
Okay. so in the end I thank you very much. My name is Michael. I'm very happy to had this course together with you, if you searching for bachelor's or master's thesis projects, remember us when you're at the end of your study and approach us. Anytime we work at the ITI, the Institute of technical informatics, we have a vet page, but we also have a discord. This Katsura wherever you post from time to time our topics for bachelor's and master's thesis.
So I will post these links also in the chat. Or you can scan the QR code if you want. So just join the discord server and you will get updated. As soon as we provide a new topic or search for students, you can do projects with us. So this 10 ECTS project, which use in every master study, I think you can do seminars with us or bachelor's master thesis, and we are also searching for PhDs. So if you want to do an academic career or scientific career, you can also do this with us to just start with a master thesis, for example.
And if you prove for yourself and And you want to continue at the university in an academic path, you can also do a dissertation. Okay. So that was it for today's lecture. I will now activate the exam in teach center. You have yeah. You have enough time to try everything out, but as you're, as I sent out in yesterday's email, you can also use this time to enter big, this big pro pattern session with your smartphone and try out the S the composition.
And try out the composition how we can do the exam next week. Because as I also wrote in the email, we have to do some cheat prevention and some measures to prevent you cheating because it's a closed book exam, and you're also have to do the exam by yourself and alone. And you're not allowed to use any lecture materials. So that's why we want to not record, but we want you to put your handy at your smartphone to decide of your desktop so that we can see your hands on the keyboard and that we can see your screen, your monitor, and we will supervise you during the exam.
Next week. And you can try this today.

Ask anything
We've read this whole study set, so questions about it get the best answers.