IEG3080 Tutorial 8 Prepared by KK. Outline Design Patterns –Creational Patterns –Structural Patterns –Behavioral Patterns Assignment 4.

Slides:



Advertisements
Similar presentations
1 Structural Design Patterns - Neeraj Ray. 2 Structural Patterns - Overview n Adapter n Bridge n Composite n Decorator.
Advertisements

18-1 Verifying Object Behavior and Collaboration Role playing – the act of simulating object behavior and collaboration by acting out an object’s behaviors.
March Ron McFadyen1 Composite Used to compose objects into tree structures to represent part-whole hierarchies Composite lets clients treat.
Patterns Reusable solutions to common object-oriented programming problems When given a programming problem, re-use an existing solution. Gang of Four.
Design Patterns Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Dept. of Computer Engineering, Amirkabir University of Tech. 1 Design Patterns Dr. Noorhosseini Introduction.
IEG3080 Tutorial 7 Prepared by Ryan.
Design Patterns CS is not simply about programming
Chapter 8, Object Design Introduction to Design Patterns
Design Patterns. What are design patterns? A general reusable solution to a commonly occurring problem. A description or template for how to solve a problem.
Design Patterns Module Name - Object Oriented Modeling By Archana Munnangi S R Kumar Utkarsh Batwal ( ) ( ) ( )
ECE 355 Design Patterns Tutorial Part 2 (based on slides by Ali Razavi) Presented by Igor Ivković
CERN – European Organization for Nuclear Research GS Department – Administrative Information Services Design Patterns in Groovy Nicolas Décrevel Advanced.
Vrije Universiteit amsterdamPostacademische Cursus Informatie Technologie Idioms and Patterns polymorphism -- inheritance and delegation idioms -- realizing.
Software Waterfall Life Cycle Requirements Construction Design Testing Delivery and Installation Operations and Maintenance Concept Exploration Prototype.
樣式導向設計 (Pattern-Oriented Design) 課程簡介 Ku-Yaw Chang Assistant Professor, Department of Computer Science and Information Engineering.
05 - Patterns Intro.CSC4071 Design Patterns Designing good and reusable OO software is hard. –Mix of specific + general –Impossible to get it right the.
An Introduction to Design Patterns. Introduction Promote reuse. Use the experiences of software developers. A shared library/lingo used by developers.
Design Pattern. The Observer Pattern The Observer Pattern defines a one-to-many dependency between objects so that when one object changes state, all.
Design Patterns CSCI 5801: Software Engineering. Design Patterns.
DESIGN PATTERNS CSC532 Adv. Topics in Software Engineering Shirin A. Lakhani.
18 April 2005CSci 210 Spring Design Patterns 1 CSci 210.
Software Design Patterns (1) Introduction. patterns do … & do not … Patterns do... provide common vocabulary provide “shorthand” for effectively communicating.
Computing IV Singleton Pattern Xinwen Fu.
Object Oriented Software Engineering Chapter 16 and 17 review 2014/06/03.
CSE 403 Lecture 14 Design Patterns. Today’s educational objective Understand the basics of design patterns Be able to distinguish them from design approaches.
SDP Structural Pattern. SDP-2 Structural Patterns Concerned with how classes and objects are composed to form large structures Class Patterns use.
Design Patterns CS 124 Reference: Gamma et al (“Gang-of-4”), Design Patterns.
Methods: Deciding What to Design In-Young Ko iko.AT. icu.ac.kr Information and Communications University (ICU) iko.AT. icu.ac.kr Fall 2005 ICE0575 Lecture.
ECE450S – Software Engineering II
Design Patterns CSIS 3701: Advanced Object Oriented Programming.
Design Pattern Dr. Zhen Jiang West Chester University url:
Introduction to Design Patterns. Questions What is a design pattern? Who needs design patterns? How different are classes and objects in APL compared.
1 Design Patterns Object-Oriented Design. 2 Design Patterns 4Reuse of design knowledge and experience 4Common in many engineering disciplines 4Avoids.
Creational Patterns
What to know for the exam. Smalltalk will be used for questions, but there will not be questions about the grammar. Questions might ask – how particular.
Proxy.
DESIGN PATTERNS COMMONLY USED PATTERNS What is a design pattern ? Defining certain rules to tackle a particular kind of problem in software development.
FACTORY METHOD. Design Pattern Space Purpose ScopeCreationalStructuralBehavioral ClassFactory MethodAdapterInterpreter Template Method ObjectAbstract.
Software Design Patterns Curtsy: Fahad Hassan (TxLabs)
CS 210 Final Review November 28, CS 210 Adapter Pattern.
Stephenson College DP 98 1 Design Patterns by Derek Peacock.
Design Patterns. 1 Paradigm4 Concepts 9 Principles23 Patterns.
Design Patterns Introduction
Design Patterns SE464 Derek Rayside images from NetObjectives.com & Wikipedia.
Design Patterns: Elements of Reusable Object – Oriented Software Web Apps and Services.
Java Design Patterns Java Design Patterns. What are design patterns? the best solution for a recurring problem a technique for making code more flexible.
COMPOSITE. Design Pattern Space Purpose ScopeCreationalStructuralBehavioral ClassFactory MethodAdapterInterpreter Template Method ObjectAbstract factory.
Example to motivate discussion We have two lists (of menu items) one implemented using ArrayList and another using Arrays. How does one work with these.
Proxy Pattern defined The Proxy Pattern provides a surrogate or placeholder for another object to control access to it by creating a representative object.
CS 210 Proxy Pattern Nov 16 th, RMI – A quick review A simple, easy to understand tutorial is located here:
Five Minute Design Patterns Doug Marttila Forest and the Trees May 30, 2009 Template Factory Singleton Iterator Adapter Façade Observer Command Strategy.
PROTOTYPE. Design Pattern Space Purpose ScopeCreationalStructuralBehavioral ClassFactory MethodAdapterInterpreter Template Method ObjectAbstract factory.
7 April 2004CSci 210 Spring Design Patterns 2 CSci 210.
Design Patterns CSCE 315 – Programming Studio Spring 2013.
Chapter 10 Design Patterns.
Chapter 5:Design Patterns
MPCS – Advanced java Programming
Design Patterns Lecture part 2.
Introduction to Design Patterns
Chapter 8, Design Patterns Bridge
object oriented Principles of software design
WARNING These slides are not optimized for printing or exam preparation. These are for lecture delivery only. These slides are made for PowerPoint 2010.
Software Engineering Lecture 7 - Design Patterns
Design Patterns in Game Design
Informatics 122 Software Design II
Informatics 122 Software Design II
CIS 644 Tues. Nov. 30, 1999 W15A … patterns.
Chapter 8, DesignPatterns Facade
Presentation transcript:

IEG3080 Tutorial 8 Prepared by KK

Outline Design Patterns –Creational Patterns –Structural Patterns –Behavioral Patterns Assignment 4

Design Patterns CreationalStructuralBehavioral Abstract Factory Builder Factory Method Prototype Singleton Adapter Bridge Composite Decorator Façade Flyweight Proxy Chain of Resp. Command Interpreter Iterator Mediator Memento Observer State Strategy Template Visitor

Design Patterns – Adapter –Adapter Convert the interface of a class into another interface clients expect. Task -Keep Target unchanged -Adapt Source interface to Target interface Adapter Client Target Source

Design Patterns – Adapter class Course { protected String code; protected String title; protected int num; public Course(String courseCode) { this.code = courseCode; } public virtual void Display() { Console.WriteLine("Course name: {0}", this.code); } Target

Design Patterns – Adapter class CourseDataBank { public String CourseTitle(String courseCode){ String title = ""; switch(courseCode.ToLower()){ case "ieg3080a" : title = "Information And Software Engineering Practice"; break; case "ieg3080b" : title = "Information And Software Engineering Practice"; break; } return title; } public int CourseStudentNum(String courseCode){ int num = 0; switch(courseCode.ToLower()){ case "ieg3080a" : num = 37;break; case "ieg3080b" : num = 97;break; } return num; } Source

Design Patterns – Adapter class Program { static void Main(string[] args) { Course course = new Course("IEG3080a"); course.Display(); Course adapter = new Adapter("IEG3080a"); adapter.Display(); Console.Read(); } Client

Design Patterns – Adapter class Adapter : Course { private CourseDataBank bank; public Adapter(String courseCode):base(courseCode) { } public override void Display() { bank = new CourseDataBank(); this.title = bank.CourseTitle(this.code); this.num = bank.CourseStudentNum(this.code); Console.WriteLine("Course name: {0}", this.code); Console.WriteLine("Course Title: {0}", this.title); Console.WriteLine("Num of Student: {0}", this.num); } Adapter

Design Patterns – Adapter

Design Patterns – Bridge –Bridge Decouple an abstraction from its implementation so that the two can vary independently. Task -No implementation in Abstraction Abstraction Implementer

Design Patterns – Bridge class Abstraction { private Implementor m_Data; public Abstraction() { } public Implementor Implementor { set { m_Data = value; } get { return m_Data; } } public virtual void PrintDeadline() { m_Data.PrintDeadline(); } class Assignment : Abstraction { } Abstraction

Design Patterns – Bridge abstract class Implementor { protected String m_name; public Implementor() { } public abstract void PrintDeadline(); } Implementer

Design Patterns – Bridge class Assignment3 : Implementor { public Assignment3(){ m_name = "Assignment3"; } public override void PrintDeadline() { Console.WriteLine("{0} Deadline : ", m_name); } class Assignment4 : Implementor { public Assignment4(){ m_name = "Assignment4"; } public override void PrintDeadline() { Console.WriteLine("{0} Deadline : ", m_name); } Implementer

Design Patterns – Bridge

Design Patterns – Composite –Composite Compose objects into tree structures to represent part-whole hierarchies. Composite lets clients treat individual objects and compositions of objects uniformly. Task -batch operation Component Leaf Composite

class Program{ static void Main(string[] args){ Composite patterns = new Composite("Design Patterns"); Composite creational = new Composite("Creational Patterns"); creational.Add(new Leaf("Abstract Factory")); creational.Add(new Leaf("Builder")); creational.Add(new Leaf("Factory Method")); creational.Add(new Leaf("Prototype")); creational.Add(new Leaf("Singleton")); patterns.Add(creational); Composite structural = new Composite("Structural Patterns"); structural.Add(new Leaf("Adapter")); structural.Add(new Leaf("Bridge")); structural.Add(new Leaf("Composite")); structural.Add(new Leaf("Decorator")); structural.Add(new Leaf("Facade")); structural.Add(new Leaf("Flyweight")); structural.Add(new Leaf("Proxy")); patterns.Add(structural); Composite behavioral = new Composite("Behavioral Patterns"); behavioral.Add(new Leaf("Chain of Resp.")); behavioral.Add(new Leaf("Command")); behavioral.Add(new Leaf("Interpreter")); behavioral.Add(new Leaf("Iterator")); behavioral.Add(new Leaf("Mediator")); behavioral.Add(new Leaf("Memento")); behavioral.Add(new Leaf("Observer")); behavioral.Add(new Leaf("State")); behavioral.Add(new Leaf("Strategy")); behavioral.Add(new Leaf("Template Method")); behavioral.Add(new Leaf("Visitor")); patterns.Add(behavioral); patterns.Display(0); Console.Read(); } Client Design Patterns – Composite

abstract class Component { protected string name; // Constructor public Component(string name) { this.name = name; } public abstract void Add(Component c); public abstract void Remove(Component c); public abstract void Display(int depth); } Component Design Patterns – Composite

class Composite : Component { private ArrayList children = new ArrayList(); public Composite(string name) : base(name) { } public override void Add(Component component){ children.Add(component); } public override void Remove(Component component){ children.Remove(component); } public override void Display(int depth) { Console.WriteLine(new String('-', depth) + name); foreach (Component component in children) { component.Display(depth + 1); } Composite Design Patterns – Composite

class Leaf : Component { public Leaf(string name) : base(name) { } public override void Add(Component c) { Console.WriteLine("Invalid"); } public override void Remove(Component c) { Console.WriteLine("Invalid"); } public override void Display(int depth) { Console.WriteLine(new String('-', depth) + name); } Leaf Design Patterns – Composite

Design Patterns – Decorator –Decorator Attach additional responsibilities to an object dynamically. Decorators provide a flexible alternative to subclassing for extending functionality. Task -Template Component Decorator

Design Patterns – Decorator abstract class Component { public abstract void Print(); } class ConcreteComponent : Component { public override void Print() { Console.WriteLine("Letter body (Component)!"); } Component

Design Patterns – Decorator class Program { static void Main(string[] args) { // Create ConcreteComponent and two Decorators ConcreteComponent letter = new ConcreteComponent(); ConcreteDecoratorA letter1 = new ConcreteDecoratorA(); ConcreteDecoratorB letter2 = new ConcreteDecoratorB(); // Link decorators letter1.SetComponent(letter); letter2.SetComponent(letter1); letter2.Print(); // Wait for user Console.Read(); } Client

Design Patterns – Decorator abstract class Decorator : Component { protected Component component; public void SetComponent(Component component) { this.component = component; } public override void Print() { if (component != null) { component.Print(); } Decorator

Design Patterns – Decorator class ConcreteDecoratorA : Decorator { private string addedState; public override void Print() { Console.WriteLine("Dear Students,"); base.Print(); addedState = "New State"; Console.WriteLine("Thanks!"); } class ConcreteDecoratorB : Decorator { public override void Print() { Console.WriteLine(" "); base.Print(); AddedBehavior(); Console.WriteLine(" "); } void AddedBehavior() { Console.WriteLine("Regards"); Console.WriteLine("KK"); } Decorator

Design Patterns – Decorator

Design Patterns – Façade –Façade Provide a unified interface to a set of interfaces in a subsystem. Façade defines a higher-level interface that makes the subsystem easier to use. Task -Linking independent classes together Facade Subsystem

Design Patterns – Façade class Program { static void Main(string[] args) { Facade facade = new Facade(); facade.MethodA(); facade.MethodB(); // Wait for user Console.Read(); } Client

Design Patterns – Façade class SubSystem1 { public void Method1() { Console.WriteLine(" SubSystem1 Method"); } class SubSystem2 { public void Method2() { Console.WriteLine(" SubSystem2 Method"); } class SubSystem3 { public void Method3() { Console.WriteLine(" SubSystem3 Method"); } Subsystem

Design Patterns – Façade class Facade { SubSystem1 sys1; SubSystem2 sys2; SubSystem3 sys3; public Facade() { sys1 = new SubSystem1(); sys2 = new SubSystem2(); sys3 = new SubSystem3(); } public void MethodA() { Console.WriteLine("\nMethodA() ---- "); sys1.Method1(); sys2.Method2(); } public void MethodB() { Console.WriteLine("\nMethodB() ---- "); sys2.Method2(); sys3.Method3(); } Facade

Design Patterns – Façade

Design Patterns References –Gamma, Erich et al, “Design Patterns: Elements of Reusable Object-Oriented Software,” Addison-Wesley. –Design Patterns with C# sample code:

Assignment 4

Create a new project, such as a Windows Application Run wsdl.exe GoogleSearch.wsdl to generate GoogleSearchService.cs, the C# client class. Add a reference to the System.Web.Services DLL to your project. Write your code to call GoogleSearchService.

Assignment 4

1 mark will be deducted if the api key is not filled in

Assignment 4 1 mark will be deducted if not fullfill this requirement

Assignment 4

eWSold.ziphttp://course.ie.cuhk.edu.hk/~ieg3080a/assignment/Googl eWSold.zip eWS.ziphttp://course.ie.cuhk.edu.hk/~ieg3080a/assignment/Googl eWS.zip 2 marks will be deducted for late submission