Studying design patterns in VB.NET
About the Design Patterns in VB.NET
Design Patterns in VB.NET is specifically designed to help Software Architects and Programmers to take advantage of Gang of Four (
GoF) design patterns so that they can build object-oriented software which is flexible, reusable and easy to maintain. You will find that application of the concepts which you learn in this school will require you to spend more time upfront, when you first design and code object-oriented programs. However, over time, the maintenance of your VB.NET, C# and Java OO-programs will become much easier, less time consuming and much less error-prone. Programmers who maintain their program functionality--which is coded using GoF design patterns--will find themselves less and less in crisis mode and increasingly able to to extend the functionality of their object-oriented programs. This holds true for both Java and .NET developers.
Prerequisites
An intermediate knowledge of object-oriented features of VB.NET is required in order to get the most from these lessons; you can learn about this in our
VB.NET School. Although the code samples use VB.NET, you will find the concepts extremely easy to apply to C# and Java, so programmers in these other languages will also feel very at home.
A good working knowledge of class diagrams is also important, but a brief primer is supplied so you can get up to speed fairly quickly.
Course Outline
Lesson 1. You Me and VB
In this first lesson, we look at who should use these tutorials (every programmer/software developer). We also look at the reasons for using VB.NET in order to illustrate design patterns. I also look a little bit at my approach to the discussion of design patterns.
Lesson 2. Abstract
Here I explain who the GoF are, what the GoF design patterns are and how they fit into the development of software. I also attempt to convince you of how crucial design patterns are to your software development efforts. The parts of each design pattern are explained broadly and I show you the principles which come together when you use design patterns. I round out the discussion with some advantages of design patterns.
Lesson 3. Guide to further reading
Even though this tutorial can be read by itself and a fairly good understanding of the patterns obtained from it, I would encourage readers to look at the design patterns from other author’s perspectives. This will reinforce your understanding, clear up misconceptions and reinforce the knowledge gained. In this lesson I suggest how to incorporate further reading into your journey through design patterns.
Lesson 4. Terms to know
In this lesson, we define the terms which the reader will need to know in order to make the best use of the Design Patterns school. They include terms which the GoF introduced and also a few terms which I coined.
Lesson 5. C++ CORGI
For those readers who are not familiar with C++ but want to learn it in order to tackle the GoF book, this section is for you. It shows you how to read C++ code in order to understand the code samples in the GoF book. If (hopefully) you find the pattern explanations adequate and do no need to revisit the GoF book, or you already know C++, then please feel free to skip this section.
Lesson 6. Structure of Patterns in the Tutorial
This article looks at the different stages through which the reader will be taken as we explore each pattern. We look at the introductory parts first and examine the methodology which will be used to ease the reader into a discussion of what the pattern is about.
Then we look at the core of the pattern which includes code snippets within the tutorial plus downloadable sample code and UMLs.
We then examine how the reader will be able to avoid common mistakes made in implementing the pattern and ensure that the pattern is implemented correctly.
Finally we look at the advanced discussions and how the reader should approach the discussions which may be useful only to those who are well grounded in their understanding of the pattern.
Creational patterns
Lesson 7. Creational Overview
We introduce the reader to creational patterns and compare the way in which a nutritionist operates, to the workings of some of the creational patterns and how this can help the reader to visualize the workings of the patterns better.
Lesson 8. Abstract Factory Pattern
Examines the Abstract Factory creational pattern. This pattern is a very easy pattern to understand. It is structurally involved but you should not let that fool you. The Abstract Factory helps you to maintain consistency within the classes in your system, so objects which work best together are used together and not with other incompatible objects.
Lesson 9. Builder PatternLooks at the Builder pattern which helps the developer to create objects in a standard manner so that product classes are delivered in a consistent way, always created in a similar process with the same steps involved.
Lesson 10. Factory Method Pattern
Factory Method is an often misunderstood pattern, both in its intent and implementation. In this article we clear up some misconceptions and help you to leverage the Factory method's power: division of programming labour which allows you to improve the security of your systems and also allow programmers to work on the parts where they have greatest expertise.
Lesson 11. Prototype Pattern
In this tutorial, we examine the old adage "don't reinvent the wheel". Here we see how we can develop prototypical instances of the classes we require to do work and deliver them to the client programs in a predictable and transparent way so the client does not need intimate knowledge of which object does what.
Lesson 12. Singleton Pattern
Too many cooks spoil the broth and so it is with situations where even one extra instantiation of a class can create a disaster in your system, since you will not be able to guarantee which object has the appropriate data.
Anyone with a kid who asks 1 parent for permission and then runs to the other when permission is denied understands this principle. Any worker who reports to two bosses understands the nightmare.
Singleton shows you how to avoid this problem in your programs. For the other, I suggest family counseling. We look at an interesting sample code which introduces a concept that will have implications for Panic Alarm systems.
Lesson 13. Creational Review
Sums up a look at the creational patterns and points out a few things to keep in mind when implementing them.
Structural patterns
Lesson 14. Structural Overview
In this lesson, you are briefly introduced to the ways in which real life situations are mirrored in the Structural patterns. We set the stage for understanding more about this second series of GoF patterns which allow us to “structure” our solutions in a manner which allows for great extinsibility.
Lesson 15. Adapter Pattern
In this tutorial,we examine the adapter pattern which is one of the most popular patterns. It allows us to adapt an existing class to new clients in a transparent maner. Hence legacy systems depend on it for compatibility most of the times. In fact .NET's interoperability with VB6 is based on the principles found in this pattern.
Lesson 16. Bridge Pattern
The Bridge pattern is something we see everyday in corporations where management figures out what should be done by creating a strategic, abstract plan of action, while employees implement the decisions taken. In this tutorial, we see where CD-players/radios and speakers/headphones model this behaviour in order to produce music. Sample code is included with GDI+ which behaves along the same principles.
Lesson 17. Composite Pattern
If you want to see an exciting and dynamic use of TreeView controls, read this article where we see the composite at work. If you remember first year of computer science, you will remember terms like breadth first, spanning trees, binary trees, depth-first search and so on. The composite pattern gives us an extremely approachable and flexible way to manage and process trees. And this tutorial shows you how to hook up your TreeViews to the tree structure which Composite presents.
Lesson 18. Decorator Pattern
Imagine what would happen if your shoes came permanently affixed to your socks. They would have to pay airport security personnel 10 times what they do, because air travellers would have extremely cheesy feet! In this article we see how the decorator allows you to add functionality to a class dynamically so that your classes don't get too heavy (or cheesy)! A dataset/datagrid sample code and 2 UML diagrams round out the discussion.
Lesson 19. Facade Pattern
There are things in life which lull us into a sense of false security. Negotiating with criminals and terrorists is one of those things. Which is why I have always respected the United States’ stance on those issues. In this tutorial, we see where the Facade mirrors this real-life situation, but in a much more positive way.
Lesson 20. Flyweight Pattern
Moviegoers will like this article since we discuss movies and actors. (If you want to find out the name of one of my favourite producers, you will even see that too!). The flyweight pattern allows us to share unchanging-objects in a memory efficient way, the same way that you can see your favourite actor in several great movies. Read this tutorial and look at the 2 UML diagrams and sample code in VB.NET to find out how.
Lesson 21. Proxy Pattern
If you have ever prayed for a friend who was being battered by life and all the difficult situations that friend was going through, then you have been “standing in the gap” for them. Put another way, you were a Proxy for that person and so you already understand the concept of the Proxy Pattern. Here we explore the ways in which General Practitioners are proxies for Dermatologists and the Police are proxies for S.W.A.T. We also see how to avoid instantiating expensive objects until absolutely required. Sample code and UML diagrams provide backup and reinforcement.
Lesson 22. Structural Review
Here we summarize what we found out in our tour through the Structural patterns.