MAHARISHI INTERNATIONAL UNIVERSITY 1971-1995 M AHARISHI U NIVERSITY of M ANAGEMENT Engaging the Managing Intelligence of Nature.

Slides:



Advertisements
Similar presentations
The Problem Decomposition of programs in terms of classes and in terms of crosscutting concerns are both useful, but languages based on source files allow.
Advertisements

CS 350 – Software Design The Bridge Pattern – Chapter 10 Most powerful pattern so far. Gang of Four Definition: Decouple an abstraction from its implementation.
Class 15 - Overhead 11Object Oriented Programming Using C #define t_circle 1 #define t_rectangle 2 struct circle_shape {short type; double x,y; double.
Object Oriented Programming
SUMMARY: abstract classes and interfaces 1 Make a class abstract so instances of it cannot be created. Make a method abstract so it must be overridden.
Chapter 14 Graph class design John Keyser’s Modifications of Slides by Bjarne Stroustrup
Reusable Classes.  Motivation: Write less code!
CS 2430 Day 28. Announcements Program 5 was posted (on Tuesday, 4/2/2013) Can work with a partner (sign up by today at 3:52pm) Exam 2 handed back on Monday.
The Bridge Pattern.. Intent Decouple an abstraction from its implementation so that the two can vary independently Also known as: Handle/Body.
More about classes and objects Classes in Visual Basic.NET.
Inheritance. Extending Classes It’s possible to create a class by using another as a starting point  i.e. Start with the original class then add methods,
MAHARISHI INTERNATIONAL UNIVERSITY M AHARISHI U NIVERSITY of M ANAGEMENT Engaging the Managing Intelligence of Nature.
MAHARISHI INTERNATIONAL UNIVERSITY M AHARISHI U NIVERSITY of M ANAGEMENT Engaging the Managing Intelligence of Nature.
MAHARISHI INTERNATIONAL UNIVERSITY M AHARISHI U NIVERSITY of M ANAGEMENT Engaging the Managing Intelligence of Nature.
MAHARISHI INTERNATIONAL UNIVERSITY M AHARISHI U NIVERSITY of M ANAGEMENT Engaging the Managing Intelligence of Nature.
MAHARISHI INTERNATIONAL UNIVERSITY M AHARISHI U NIVERSITY of M ANAGEMENT Engaging the Managing Intelligence of Nature.
CS221 - Computer Science II Polymorphism 1 Inheritance "Question: What is the object oriented way of getting rich? Answer: Inheritance.“ “Inheritance is.
CS 2511 Fall UML Diagram Types  2 Main Types Structure Diagrams ○ Class Diagrams ○ Component Diagrams ○ Object Diagrams Behavior Diagrams ○
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. The Factory Method Design Pattern (1) –A creational design.
Sadegh Aliakbary Sharif University of Technology Fall 2010.
Using Jeroo To Teach Object-Oriented Concepts By Christian Digout.
Sadegh Aliakbary. Copyright ©2014 JAVACUP.IRJAVACUP.IR All rights reserved. Redistribution of JAVACUP contents is not prohibited if JAVACUP.
CS 4240: Bridge and Abstract Factory Readings:  Chap. 10 and 11 Readings:  Chap. 10 and 11.
© opyright for Students and Educators 2011 NOTE: This presentation is for information only and is not intended as legal advice. For legal advice, please.
SE2811 Week 7, Class 1 Composite Pattern Applications Conceptual form Class structure Coding Example Lab Thursday: Quiz SE-2811 Slide design: Dr. Mark.
CS305j Introduction to Computing Inheritance and Polymorphism 1 Topic 26 Introduction to Inheritance and Polymorphism "One purpose of CRC cards [a design.
Computer Science [3] Java Programming II - Laboratory Course Lab 1 + 2: Review inheritance & abstract Review inheritance & abstractPolymorphism Faculty.
Programming With Java ICS Chapter 8 Polymorphism.
Object-Oriented Software Engineering Practical Software Development using UML and Java Chapter 5: Modelling with Classes.
Chris Kiekintveld CS 2401 (Fall 2010) Elementary Data Structures and Algorithms Inheritance and Polymorphism.
Programming With Java ICS201 University Of Hail1 Chapter 13 Interfaces.
Polymorphism. 3 main programming mechanisms that constitute OOP: 1. Encapsulation 2. Inheritance 3. Polymorphism.
Inheritance Chapter 10 Programs built from objects/instances of classes An O.O. approach – build on earlier work. Use classes in library and ones you have.
Copyright (c) 1998, 1999 D.L. Bailey * Winter 1999 Part 6 Reusing Classes: Inheritance and Composition.
Peyman Dodangeh Sharif University of Technology Fall 2014.
Inheritance CSI 1101 Nour El Kadri. OOP  We have seen that object-oriented programming (OOP) helps organizing and maintaining large software systems.
CIS3023: Programming Fundamentals for CIS Majors II Summer 2010 Ganesh Viswanathan Abstract Classes Course Lecture Slides 7 June 2010 “None of the abstract.
Bridge Bridge is used when we need to decouple an abstraction from its implementation so that the two can vary independently. This type of design pattern.
Design Patterns: Structural Design Patterns General and reusable solutions to common problems in software design Software University
Chapter Ten The Bridge Pattern Ku-Yaw Chang Assistant Professor, Department of Computer Science and Information Engineering Da-Yeh.
1 Interfaces and Abstract Classes The ability to define the behavior of an object without specifying that behavior is to be implemented Interface class.
Interfaces, Abstract Classes, and Polymorphism. What Is an Interface? An interface is the set of public methods in a class Java provides the syntax for.
TK2023 Object-Oriented Software Engineering CHAPTER 11 CLASS DIAGRAMS.
CS 350 – Software Design The Decorator Pattern – Chapter 17 In this chapter we expand our e-commerce case study and learn how to use the Decorator Pattern.
Abstract Classes. Recall We have the ability to create hierarchies of classes. Good design practice suggests that we move common methods as high as possible.
CS 116 Object Oriented Programming II Acknowledgement: Contains materials provided by George Koutsogiannakis and Matt Bauer.
Abstract Classes, Abstract Methods, Override Methods
OCP and Liskov Principles
Advanced Programming in Java
Inheritance ITI1121 Nour El Kadri.
Abstraction, Interface, Inheritance, Polymorphism, Override / Overload
Interface.
Advanced Programming in Java
Section 11.1 Class Variables and Methods
Composite Pattern SE2811 Software Component Design
CS250 Introduction to Computer Science II
Inheritance "Question: What is the object oriented way of getting rich? Answer: Inheritance.“ “Inheritance is new code that reuses old code. Polymorphism.
CSC 205 Programming II Lecture 2 Subclassing.
OBJECT ORIENTED PROGRAMMING II LECTURE 8 GEORGE KOUTSOGIANNAKIS
Week 6 Object-Oriented Programming (2): Polymorphism
Advanced Programming Behnam Hatami Fall 2017.
Practical Session 2 Class Design
Subtype Polymorphism, Subtyping vs
Announcements & Review
The Adapter Pattern.
13. Composite Pattern SE2811 Software Component Design
13. Composite Pattern SE2811 Software Component Design
OOP Aga private institute for computer science 5th grade
INTERFACES Explained By: Sarbjit Kaur. Lecturer, Department of Computer Application, PGG.C.G., Sector: 42, Chandigarh.
Presentation transcript:

MAHARISHI INTERNATIONAL UNIVERSITY M AHARISHI U NIVERSITY of M ANAGEMENT Engaging the Managing Intelligence of Nature

CS Faculty Computer Science Department Advanced Software Development

Lab 8: Patterns: Bridge Lab

Bridge : Motivation 2

Bridge : Structure

Bridge : Example 2

class Client { public static void main (String argv[]) { Rectangle s1, s2; s1= new V1Rectangle( (double)1,(double)1,(double)2,(double)2); s2= new V2Rectangle( (double)1,(double)1,(double)3,(double)3); s1.draw(); s2.draw(); } Bridge : Example 2

public abstract class Rectangle { double _x1, _y1,_x2,_y2; public Rectangle( double x1, double y1, double x2, double y2) { _x1= x1; _y1= y1; _x2= x2; _y2= y2; } public void draw () { drawLine(_x1, _y1, _x1, _y2); drawLine(_x1, _y1, _x2, _y1); drawLine(_x1, _y2, _x2, _y2); drawLine(_x2, _y1, _x2, _y2); } abstract void drawLine ( double x1, double x2, double y1, double y2); } public class V1Rectangle extends Rectangle { public V1Rectangle( double x1, double y1, double x2, double y2) { super(x1,y1,x2,y2); } public void drawLine( double x1, double y1,double x2, double y2) { DP1.draw_a_line( x1,y1,x2,y2); } class V2Rectangle extends Rectangle { public V2Rectangle( double x1, double y1, double x2, double y2) { super(x1,y1,x2,y2); } public void drawLine(double x1, double y1,double x2, double y2) { DP2.drawline( x1,x2,y1,y2); }

class DP1 { static void draw_a_line ( double x1, double y1,double x2, double y2) { String sx1=String.valueOf(x1); String sy1=String.valueOf(y1); String sx2=String.valueOf(x2); String sy2=String.valueOf(y2); System.out.println("DP1: draw line: x1="+sx1+" y1="+sy1+" x2="+sx2+" y2="+sy2); } static void draw_a_circle( double x, double y, double radius) { String sx=String.valueOf(x); String sy=String.valueOf(y); String sradius=String.valueOf(radius); System.out.println("DP1: draw circle: x="+sx+" y="+sy+" radius="+sradius); }} class DP2 { static void drawline ( double x1, double y1, double x2, double y2) { String sx1=String.valueOf(x1); String sy1=String.valueOf(y1); String sx2=String.valueOf(x2); String sy2=String.valueOf(y2); System.out.println("DP2: draw line: x1="+sx1+" y1="+sy1+" x2="+sx2+" y2="+sy2); } static void drawcircle( double x, double y,double radius) { String sx=String.valueOf(x); String sy=String.valueOf(y); String sradius=String.valueOf(radius); System.out.println("DP2: draw circle: x="+sx+" y="+sy+" radius="+sradius); }

Bridge : Example 2

Get New Requirements Told we must now handle Circles I decide to handle it in a similar way. Make a V1Circle class and a V2Circle class. Tie Circles and Rectangles together by having them derive from new Shape class. Bridge : Example 2

class Client { public static void main (String argv[]) { Shape s1, s2, s3, s4; s1= new V1Rectangle( (double)1,(double)1,(double)2,(double)2); s2= new V2Rectangle( (double)1,(double)1,(double)3,(double)3); s3=new V1Circle((double)1,(double)1,(double)3); s4=new V2Circle((double)4,(double)1,(double)2); s1.draw(); s2.draw(); s3.draw(); s4.draw(); } abstract class Shape { abstract public void draw (); } Bridge : Example 2

public abstract class Rectangle extends Shape { double _x1, _y1,_x2,_y2; public Rectangle( double x1, double y1, double x2, double y2) { _x1= x1; _y1= y1; _x2= x2; _y2= y2; } public void draw () { drawLine(_x1, _y1, _x1, _y2); drawLine(_x1, _y1, _x2, _y1); drawLine(_x1, _y2, _x2, _y2); drawLine(_x2, _y1, _x2, _y2); } abstract void drawLine ( double x1, double x2, double y1, double y2); } public abstract class Circle extends Shape { protected double _x, _y, _radius; public Circle (double x, double y, double radius) { _x= x; _y= y; _radius= radius; } public abstract void draw (); }

Bridge : Example 2 public class V1Rectangle extends Rectangle { public V1Rectangle( double x1, double y1, double x2, double y2) { super(x1,y1,x2,y2); } public void drawLine( double x1, double y1,double x2, double y2) { DP1.draw_a_line( x1,y1,x2,y2); } class V2Rectangle extends Rectangle { public V2Rectangle( double x1, double y1, double x2, double y2) { super(x1,y1,x2,y2); } public void drawLine(double x1, double y1,double x2, double y2) { DP2.drawline( x1,x2,y1,y2); }

Bridge : Example 2 class V1Circle extends Circle { public V1Circle (double x, double y, double radius){ super(x, y, radius); } public void draw () { DP1.draw_a_circle(_x,_y,_radius); } class V2Circle extends Circle { public V2Circle (double x, double y, double radius){ super(x, y, radius); } public void draw () { DP2.drawcircle( _x,_y,_radius); }

Bridge : Example 2 Problems With This Approach Doesn’t scale well –if add another type of Shape, we have 6 implementations –number of implementations will equal # types of Shapes times # of drawing programs Redundancy –clearly accessing each of the drawing programs across the different types of Shapes will involve duplication or require greater modularization Confusing and complex

Bridge : Example 2 Changing the inheritance hierarchy doesn’t get rid of the problems

Bridge : Lab Solution: Use the Bridge pattern. Exercise: Draw the class diagram of our drawing application with the Bridge pattern applied. Lab: implement the drawing application with the Bridge pattern applied.

© 2000 Maharishi University of Management, Fairfield, Iowa, USA This tape may not be copied, duplicated, or distributed without written consent from Maharishi University of Management, Fairfield, Iowa, USA.

® Science of Creative Intelligence is a service mark registered in the United States Patent and Trademark Office, licensed to Maharishi Vedic Education Development Corporation, and is used under sublicense.