For my previous English class a had a task to create a presentation on design. This topic was pretty hard for me because I am not very good at describing design and I am not an expert in it!
I’ve spent nearly 2 hours just to choose what I wanted to speak about in my presentation. And finally I came up with an idea to create a presentation about software design patterns. I know, it is rather boring topic to speak about because is quite technical, but I’m just know about it way more than I know about design of furniture or design of cars.
Presentation: Software Design Patterns
Good morning everyone. My name is Anton. I’m a student of MIPT. Today in my presentation, I’m going to speak about Software Design patterns. My presentation will take about 15 minutes. Feel free to interrupt me and ask a question.
The plan of my presentation is shown on the slide. Let’s start!
Simplicity is the soul of efficiency.
— Austin Freeman, “The Eye of Osiris”
The first thing I want to tell you about is what a software design pattern is. Does anyone know the answer to this question?
In software engineering, a design pattern is a general repeatable solution to a commonly occurring problem in software design. A design pattern isn’t a finished design that can be transformed directly into code. It is a description or template for how to solve a problem that can be used in many different situations.
Now that we know what it is we can move on to the question “Why do we use design patterns?”
Why do we use design patterns?
Design patterns can speed up the development process by providing tested, proven development paradigms. Effective software design requires considering issues that may not become visible until later in the implementation. Reusing design patterns helps to prevent subtle issues that can cause major problems in the future.
In addition, patterns allow developers to communicate using well-known, well understood names for software interactions. More than that, common design patterns can be improved easily.
Also, design patterns improve code readability for coders and solution architects. The code becomes understandable and maintainable.
So, the design patterns is actually a good thing! And there are over 30 patterns to solve almost any problem. This brings me to the next point.
Classification of design patterns
There are a lot of design patterns and they all are divided into four classes: creational, structural, behavioural, and concurrent.
Creational design patterns
These design patterns are all about class instantiation. This pattern can be further divided into class-creation patterns and object-creational patterns. While class-creation patterns use inheritance effectively in the instantiation process, object-creation patterns use delegation effectively to get the job done.
Structural design patterns
These design patterns are all about Class and Object composition. Structural class-creation patterns use inheritance to compose interfaces. Structural object-patterns define ways to compose objects to obtain new functionality.
Behavioural design patterns
These design patterns are all about Class’s objects communication. Behavioural patterns are those patterns that are most specifically concerned with communication between objects.
These patterns help to control the execution flow of the applications and provide solutions to problem of concurrent access.
Now, lets have a look at an example of a simple but very useful creational design pattern – Singleton
- Ensure a class has only one instance, and provide a global point of access to it.
- Encapsulated “just-in-time initialization” or “initialization on first use”.
Application needs one, and only one, instance of an object. Additionally, lazy initialization and global access are necessary.
Singleton should be considered only if all three of the following criteria are satisfied:
- Ownership of the single instance cannot be reasonably assigned
- Lazy initialization is desirable
- Global access is not otherwise provided for
The example of the implementation of Singleton in Java you can see on the slide.
The main disadvantages of this implementation are that deleting a Singleton class/instance is a non-trivial design problem and this implementation is not thread-safe.
OK. Design patters are good. But what about the other side of the coin? Let’s have look at its bad points.
The concept of design patterns has been criticized by some in the field of computer science.
Targets the wrong problem
The need for patterns results from using computer languages or techniques with insufficient abstraction ability. Under ideal factoring, a concept should not be copied, but merely referenced. But if something is referenced instead of copied, then there is no “pattern” to label and catalogue. Paul Graham writes in the essay Revenge of the Nerds.
Peter Norvig provides a similar argument. He demonstrates that 16 out of the 23 patterns in the Design Patterns book (which is primarily focused on C++) are simplified or eliminated (via direct language support) in Lisp or Dylan.
Lacks formal foundations
The study of design patterns has been excessively ad-hoc, and some have argued that the concept sorely needs to be put on a more formal footing. At Oopsla 1999, the Gang of Four were (with their full cooperation) subjected to a show trial, in which they were “charged” with numerous crimes against computer science. They were “convicted” by ⅔ of the “jurors” who attended the trial.
Leads to inefficient solutions
The idea of a design pattern is an attempt to standardize what are already accepted best practices. In principle this might appear to be beneficial, but in practice it often results in the unnecessary duplication of code. It is almost always a more efficient solution to use a well-factored implementation rather than a “just barely good enough” design pattern.
And final bad point is that design patterns are very bad when they are used improperly or overused. So, DO NOT OVERUSE IT!
Let’s move on to my next point which I want to cover in my presentation.
Anti-patterns are complete opposite to patterns. Patterns, as you now know, are the examples of good programming practice. In contrast, anti-patterns are the examples of mistakes, which are made in solving different problems.
Here are the most common anti-patterns:
- Copy and Paste Programming
- Spaghetti Code
- Golden Hammer
- Magic Numbers
- Hard Code
- Soft Code
- Reinventing the Wheel
- Reinventing the Square Wheel
- Blind Faith
- Brute Force Coding
- Boat Anchor
- God Object
- Unnecessary comments
Now, I’d like to make a conclusion to my whole presentation. Let’s go over the main points.
- Design pattern is a general solution to a commonly occurring problem in software design
- Using design patterns makes your code better
- Design patterns are divided into:
- Do NOT OVERUSE design patterns
- Creating your software avoid anti-patterns.
Here you may find all about software design patterns and anti-patterns.
Thank you very much for your attention! 🙂
Download my presentation: Software Design Patterns (.pps, 500 kB)
If you find any mistake, let me know. Good luck with your English.
P.S. My presentation should have been shorter. But it is not possible to cover this topic in 10 minutes! Sorry, my dear teacher. I should have also learn the speech by heart, but we had too little time to get prepared. 🙂