Week 1 Subject Introduction: Design Patterns PDF
Document Details
Uploaded by SweepingArcticTundra565
Siti Fazilah
Tags
Summary
This document introduces design patterns as a set of solutions to recurring design problems for software. It identifies different categories of design patterns and explains their roles, including the importance of design vocabulary to software discussions. The document covers software architecture, different design patterns, and details about various types of design pattern.
Full Transcript
Hello and Welcome ! XBSE2034N SOFTWARE DESIGN Siti Fazilah Subject Synopsis Software Design in general describe the best practices for a specific type of design problem based on the fundamental design principles. Low-level software design patterns deal with the inter...
Hello and Welcome ! XBSE2034N SOFTWARE DESIGN Siti Fazilah Subject Synopsis Software Design in general describe the best practices for a specific type of design problem based on the fundamental design principles. Low-level software design patterns deal with the internal software quality attributes. High-level architectural design patterns deal with the external software quality attributes. This course teaches students how to design quality software systems by applying both the software and architectural design patterns. In this course, application of design patterns is based on object-oriented methodology. Learning Outcome At the end of the course the students will be able to: Identify and describe software design fundamentals Design an application based on specific requirements. Present the designs and justify how it meets specified requirements. WEEK 1 Introduction to Design Patterns Software Architectures A Software Architecture provides a fundamental description of a system, detailing the components that make up the system and the meaningful collaborations among those components, including the data and control flows of the system Architectural Archetypes The design of a software architecture can be driven by other architectures On a lower scale, reusable microarchitectures are called “design patterns” Patterns in Architecture Does this room interior make you feel happy? Christopher Alexander The architect Alexander introduced the concept of a pattern language in his book The Timeless Way of Building. He introduces the concept of a pattern language, as a related set of patterns that together provide a vocabulary for designing within a certain context or problem domain. Examples of Alexander's patterns are: Town patterns Ring roads, night life, and row houses Building patterns Roof garden, indoor sunlight, and alcoves Construction patterns Good materials, column connection, and half-inch trim What are typical software design problems? Typical design problems What design issues can I reuse? Which design vocabulary can I use? How can I say that I found a good design solution? How can I simplify a design What are Design Patterns? Design Pattern many ways to time some Why? deal with these solutions are because they're recurring preferred over more flexible or problems others reusable A design pattern is a practical proven solution to a recurring design problem. Design Pattern Think of design pattens like the way you would think of recipes in cooking. Over the years, developers have experimented with many different design solutions. And these design patterns outline solutions that often create the best outcome. Design Patterns Design patterns are reusable (“template”) designs that can be used in a variety of ways in different systems. They are appropriate in situations where classes are likely to be reused in a system that evolves over time 23 Design Patterns Experience Matters….. Using design patterns is sort of like playing a game of chess. There are many ways to win by putting your opponent in checkmate A beginner chess player may only know the basic moves of each piece. Whereas an expert chess player will look for appropriate patterns on the board Similar to chess, beginner software developers might only know the elements of language syntax in programming software. They know elements like how to create a for loop, a method, and so on. But with more practice and experience, they can code using common conventions. They can become design experts who know the design patterns to use in solving particular software design problems. Design patterns are conceptual Design patterns is not a concrete set of source code that you memorize and put into your software, like Java libraries or frameworks Design patterns are a bit more conceptual Used to guide structure of software Used to make software more flexible and reusable So, why should you use design patterns? Design patterns help software developers so that instead of building everything from scratch, they have a guide that helps them solve design problems in the way experts do. Design Vocabulary Design patterns help to create a design vocabulary We can simplify the discussion by having a suggestive word to describe the design solution. For example, there's a very common design problem in software where you have two objects and the first object depends on the second object. If the second object changes, the first object should be notified. This is a situation that occurs often in software and we take some time during the discussion to describe a solution involving super classes or interphases and certain methods. Design patterns help to address issue by giving each pattern a name and making it easier for developers to communicate. Prior knowledge of this particular pattern outlines a solution and clarifies the original situation. Knowledge of design patterns leaves less room for misunderstanding. Background In 1987 Cunningham and Beck worked with Smalltalk and found some patterns when designing GUIs Concept popularized in a book by Gamma, Helm, Johnson and Vlissides (The “Gang of four”, Go4): they were working on frameworks (E++, Unidraw, HotDraw) The Gang of Four Why do designers need patterns? Reusing design knowledge Reusing existing experience might be useful Establish a common terminology Provide a higher level prospective Patterns are a “design reference” Evolution of Design Patterns Gang of Four’s Pattern Catalogue The four authors of the famous book Design Patterns: Elements of Reusable Object-Oriented Software – Gamma, Helm, Johnson, and Vlissides – collectively nicknamed the Gang of Four The patterns developed by the Gang of Four were organized to be readable, and often named after their purpose. The grouping of patterns together forms a catalog, otherwise known as the Gang of Four’s design pattern catalog. Explained design patterns as a list of tropes. Pattern Languages The patterns and solutions of the Gang of Four’s catalog serve a variety of different purposes. Depending on the context of the problem, you would select a different pattern language to use. So, what is a pattern language? A pattern language is a collection of patterns that are related to a certain problem space. For example, the pattern language you select for designing accounting software would be different than those you select for designing gaming software. Structure of a design pattern 1. Pattern Name and Classification 2. Intent 3. Motivation 4. Applicability 5. Structure 6. Participants 7. Collaborations 8. Consequences 9. Implementation Software Design & Architecture Stack The Gang of Four’s pattern catalog contains 23 patterns. These patterns can be sorted into three different categories: creational patterns structural patterns Categories of Patterns behavioural patterns Classification of GoF Patterns Creational Patterns Creational patterns deal with the creation or cloning new objects. Cloning an object occurs when you are creating an object that is similar to an existing one, and instead of instantiating a new object, you clone existing objects instead of instantiating them. Creational patterns depend on the programming language being used. Structural Patterns Structural patterns describe how objects are connected to each other. These patterns relate to the design principles of decomposition and generalization Not only do structural patterns describe how different objects have relationships, but also how subclasses and classes interact through inheritance. Behavioural Patterns Behavioural patterns focus on how objects distribute work Describe how each object does a single cohesive function. Focus on how independent objects work towards a common goal. Singleton Pattern A singleton is a creational pattern, which describes a way to create an object. Simplest examples of a design pattern. In a singleton design pattern only has one object of a class. Another goal of singleton design pattern is that the single object is globally accessible within the program. In order to implement a singleton design pattern, best practice is to build the “one and only one” goal into the class itself, Singleton Pattern Let us examine this in code. If a class has a public constructor, an object of this class can be instantiated at any time. Singleton Pattern First, declare a class variable. In this case, it is called “uniqueInstance”. This class variable will refer to the one instance of your Singleton class. As the variable is private, it can only be modified within the class. Second, create a public method in the class that will create an instance of this class, but only if an instance does not exist already. In this case, the method is called “getInstance” An advantage of this version of a Singleton class is lazy creation. Lazy creation means that the object is not created until it is truly needed. Advantage of Singleton The intent of a Singleton pattern is to provide global Pattern access to a class that is restricted to one instance.