IEG3080 Tutorial 7 Prepared by Ryan.

Slides:



Advertisements
Similar presentations
Welcome to. Who am I? A better way to code Design Patterns ???  What are design patterns?  How many are there?  How do I use them?  When do I use.
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.
DESIGN PATTERNS OZGUR RAHMI DONMEZ.
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.
05/26/2004www.indyjug.net1 Indy Java User’s Group June Knowledge Services, Inc.
Design Patterns A brief introduction to what they are, why they are useful, and some examples of those that are commonly used.
(c) 2009 University of California, Irvine – André van der Hoek1June 13, 2015 – 21:42:16 Informatics 122 Software Design II Lecture 8 André van der Hoek.
Dept. of Computer Engineering, Amirkabir University of Tech. 1 Design Patterns Dr. Noorhosseini Introduction.
Design Patterns CS is not simply about programming
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.
Spring 2010CS 2251 Design Patterns. Spring 2010CS 2252 What is a Design Pattern? "a general reusable solution to a commonly occurring problem in software.
DESIGN PATTERNS Redesigning Applications And
Design Patterns Module Name - Object Oriented Modeling By Archana Munnangi S R Kumar Utkarsh Batwal ( ) ( ) ( )
Design Patterns academy.zariba.com 1. Lecture Content 1.What are Design Patterns? 2.Creational 3.Structural 4.Behavioral 5.Architectural 6.Design Patterns.
Vrije Universiteit amsterdamPostacademische Cursus Informatie Technologie Idioms and Patterns polymorphism -- inheritance and delegation idioms -- realizing.
Design Patterns.
Software Waterfall Life Cycle Requirements Construction Design Testing Delivery and Installation Operations and Maintenance Concept Exploration Prototype.
05 - Patterns Intro.CSC4071 Design Patterns Designing good and reusable OO software is hard. –Mix of specific + general –Impossible to get it right the.
CSSE 374: Introduction to Gang of Four Design Patterns
An Introduction to Design Patterns. Introduction Promote reuse. Use the experiences of software developers. A shared library/lingo used by developers.
SOEN 6011 Software Engineering Processes Section SS Fall 2007 Dr Greg Butler
Patterns in programming 1. What are patterns? “A design pattern is a general, reusable solution to a commonly occurring problem in software. A design.
SOFTWARE DESIGN AND ARCHITECTURE LECTURE 27. Review UML dynamic view – State Diagrams.
SOEN 343 Software Design Section H Fall 2006 Dr Greg Butler
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.
L11-12: Design Patterns Definition Iterator (L4: Inheritance)‏ Factory (L4: Inheritance)‏ Strategy (L5: Multiple Inheritance)‏ Composite (L6: Implementation.
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.
Design Patterns CS 124 Reference: Gamma et al (“Gang-of-4”), Design Patterns.
CSE 403, Spring 2008, Alverson Software Design “There are two ways of constructing a software design: one way is to make it so simple that there are obviously.
Design Principle & Patterns by A.Surasit Samaisut Copyrights : All Rights Reserved.
ECE450S – Software Engineering II
Patterns in programming1. 2 What are patterns? Answers to common design problems. A language used by developers –To discuss answers to design problems.
Design Patterns CSIS 3701: Advanced Object Oriented Programming.
Introduction to Design Patterns. Questions What is a design pattern? Who needs design patterns? How different are classes and objects in APL compared.
Creational Patterns
DESIGN PATTERNS Sanjeeb Kumar Nanda 30-Aug What is a pattern? Pattern is a recurring solution to a standard problem Each Pattern describes a problem.
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.
Behavioral Patterns CSE301 University of Sunderland Harry R Erwin, PhD.
Copyright © Active Frameworks Inc. - All Rights Reserved - V2.0Design Pattern Catalog - Page L3-1 PS95&96-MEF-L10-1 Dr. M.E. Fayad Creationa.
Software Design Patterns Curtsy: Fahad Hassan (TxLabs)
Design Patterns. 1 Paradigm4 Concepts 9 Principles23 Patterns.
Design Patterns Introduction
Design Patterns SE464 Derek Rayside images from NetObjectives.com & Wikipedia.
Java Design Patterns Java Design Patterns. What are design patterns? the best solution for a recurring problem a technique for making code more flexible.
Interface Patterns. Adapter Provides the interface a client expects, using the services of a class with a different interface Note Avoid using object.
Five Minute Design Patterns Doug Marttila Forest and the Trees May 30, 2009 Template Factory Singleton Iterator Adapter Façade Observer Command Strategy.
Design Patterns Creational Patterns. Abstract the instantiation process Help make the system independent of how its objects are created, composed and.
CLASSIFICATION OF DESIGN PATTERNS Hladchuk Maksym.
Design Patterns CSCE 315 – Programming Studio Spring 2013.
Design Patterns: MORE Examples
Design Patterns: Brief Examples
Design Patterns Spring 2017.
Chapter 10 Design Patterns.
Chapter 5:Design Patterns
Software Design Patterns
MPCS – Advanced java Programming
Design Patterns Lecture part 2.
Introduction to Design Patterns
Design Patterns with C# (and Food!)
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
Informatics 122 Software Design II
Informatics 122 Software Design II
Presentation transcript:

IEG3080 Tutorial 7 Prepared by Ryan

Outline Design Patterns Assignment 3 Creational Patterns Structural Patterns Behavioral Patterns Assignment 3

Design Patterns What’s Design Patterns? General recurring solutions to some common software design problems and to make the designs more flexible and reusable Descriptions of relationship and interaction between objects or classes that are customized to solve a general design problem in a particular context

Design Patterns Reuse Mechanisms in Design Patterns Class Inheritance White-box reuse The internals of parent classes are often visible to the subclass Reuse by subclassing Object Composition Black-box reuse The internals of objects are encapsulated Reuse by assembling/composing objects

Design Patterns The principles of good object-oriented design Program to an (abstract) interface, not an (concrete) implementation Reduce implementation dependencies By declaring variables to be instances of an abstract class (interface) Favor object composition over class inheritance (object composition) defined dynamically at run-time, (class inheritance) defined at compile-time Keep each class encapsulated and focused on one task

Design Patterns “Gang of Four” Design Patterns – total 23 patterns Creational Patterns (5) The process of object creation Structural Patterns (7) The composition of objects or classes Behavioral Patterns (11) The way in which objects or classes interact and distribute responsibility

Design Patterns Creational Structural Behavioral 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 – Creational Abstract Factory Provide an interface for creating families of related or dependent objects without specifying their concrete classes. class Shop { Product product; public Shop(AbstractFactory a) { p = a.CreateProduct1(); p = a.CreateProduct2(); } abstract class AbstractFactory { public abstract Product CreateProduct1(); public abstract Product CreateProduct2(); The “product” being created depends on the “factory”

Design Patterns – Creational Builder Separate the construction of a complex object from its representation so that the same construction process can create different representations. class Shop { Product p; public Shop(Builder b) { b.CreateSubProduct1(); b.CreateSubProduct2(); p = b.GetProduct(); } abstract class Builder { public abstract void CreateSubProduct1(); public abstract void CreateSubProduct2(); public abstract Product GetProduct(); “Parts” of the complex object is encapsulated inside the builder The complex object is returned as a final step

Design Patterns – Creational Factory Method Define an interface for creating an object, but let subclasses decide which class to instantiate. Factory Method lets a class defer instantiation to subclasses. abstract class Shop { protected Product p; public Shop() { CreateProduct(); } public abstract void CreateProduct(); class Shop1 : Shop { public override void CreateProduct() { p = new Product1(); } class Shop2 : Shop { p = new Product2(); Subclasses define the object to be created

Design Patterns – Creational Prototype Specify the kind of objects to create using a prototypical instance, and create new objects by copying this prototype. class Shop { Product p, p2; public Shop() { p = new Product(); p2 = p.Clone(); } abstract class Prototype { public abstract Prototype Clone(); class Product : Prototype { public override Prototype Clone() { return (Prototype)this.MemberwiseClone(); A object is created by copying (clone)

Design Patterns – Creational Singleton Ensure a class has only one instance and provide a global point of access to it. class Singleton {      private static Singleton instance;      protected Singleton() { }      public static Singleton Instance() {       if (instance == null)        {          instance = new Singleton();        }        return instance;      } } class Test { public static void Main() {            Singleton s1 = Singleton.Instance(); Private constructor

Design Patterns – Creational Summary Abstract Factory Create a family of objects by a “factory object” Builder Create complex objects with different representations by a “builder object” Factory Method Provide an interface for objects creation, specify the objects to be created in the subclass Prototype Create new objects by copying Singleton Allow only one instance of a class

Design Patterns References Gamma, Erich et al, “Design Patterns: Elements of Reusable Object-Oriented Software,” Addison-Wesley. Design Patterns with C# sample code: http://www.dofactory.com/Patterns/Patterns.aspx

Assignment 3 Use a type-safe container (Array/ArrayList) to store objects Implement IComparable interface to support built-in Sort method .NET Framework Class Library Interface IComparable { int CompareTo(object o); } Method “CompareTo()” return value Less than 0: this instance is less than object 0: this instance is equal to object Greater than 0: this instance is greater than object

Assignment 3 Sample Code // Type-safe ArrayList // Implement IEnumerable interface class CustomerList : IEnumerable { ArrayList list; public CustomerList() { list = new ArrayList(); } public void Add(Customer c) { list.Add(c); public IEnumerator GetEnumerator() { return list.GetEnumerator(); public void Sort() { list.Sort(); // ArrayList built-in Sort() method // Implement IComparable interface class Customer : IComparable { string customer_name; public Customer(string name) { customer_name = name; } // Implement IComparable.CompareTo() public int CompareTo(object o) { Customer temp = (Customer)o; //Type casting to “Customer” return customer_name.CompareTo(temp.customer_name); // Other Methods ……

Assignment 3 Implement a GUI for Assignment 2 program Menu Bar – “List” and “Home” buttons 1) Click “List” Show a SORTED list of customers in the panel (sorted by customer name)

Assignment 3 2) Click a customer name Show the accounts belonging to the selected customer 3) Select and Right-click an account Show a menu with “Deposit” and “Withdraw” buttons 4) Click “Deposit”/”Withdraw” Pop up a window with a text box and a “Confirm” button 5) Input an amount in the text box and Click “Confirm” Close the window and Perform deposit/withdraw action Show the updated account summary 6) Click “Home” Return to the home page

Assignment 3 Drag and Drop Components to the Window Form Some useful components MenuStrip ContextMenuStrip Shortcut menu when the user right-clicks the associated control TreeView TextBox Button TextBox MenuStrip Label ContextMenuStrip Button TreeView

Assignment 3 Programming with the components Double-click the components, Click event handler method will be generated automatically More about TreeView Add a node in TreeView myTreeView.Nodes.Add(“myNode1”); Add a node associated with ContextMenuStrip TreeNode myNode = new TreeNode(); myNode.Text = “myNode1”; myNode.ContextMenuStrip = myContextMenuStrip; myTreeView.Nodes.Add(myNode); Add an event handler method for mouse right-click myTeeView.NodeMouseClick += new System.Windows.Forms.TreeNodeMouseClickEventHandler(myHandler); private void myHandler(object sender, TreeNodeMouseClickEventArgs e) { if (e.Button == MouseButtons.Right) { /* Your code here. You can get the clicked Node by “e.Node” */ } }