Presentation is loading. Please wait.

Presentation is loading. Please wait.

SWE 316: Software Design and Architecture Objectives Lecture 3 Object Orientation SWE 316: Software Design and Architecture NOTE: most slides are adapted.

Similar presentations


Presentation on theme: "SWE 316: Software Design and Architecture Objectives Lecture 3 Object Orientation SWE 316: Software Design and Architecture NOTE: most slides are adapted."— Presentation transcript:

1 SWE 316: Software Design and Architecture Objectives Lecture 3 Object Orientation SWE 316: Software Design and Architecture NOTE: most slides are adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission. Ch 2

2 SWE 316: Software Design and Architecture Before Object Orientation Real world concepts Software Design Entities Skljkvjkvjfkavjafkk saovjsdvjfvkfjvkfjk Skljkvjkvjfkavjafkk saovjsdvjfvkfjvkfjk Skljkvjkvjfkavjafkk saovjsdvjfvkfjvkfjk Skljkvjkvjfkavjafkk saovjsdvjfvkfjvkfjk Object Orientation Classes and ObjectsExamplePolymorphismInterfacesThings to be considered 2/24

3 SWE 316: Software Design and Architecture Goals of Object Orientation How Do We Express Ourselves? "Customers Montague and Susan entered the Ajax bank and were served by teller Andy..... " AJAX BANK Sec 2.1 page 44 Object Orientation Classes and ObjectsExamplePolymorphismInterfacesThings to be considered 3/24

4 SWE 316: Software Design and Architecture How We Express Ourselves " Customer s Montague and Susan entered the Ajax bank and were served by teller Andy..... " CLASSES OBJECTS Note that Java code convention reverses this capitalization. Object Orientation Classes and ObjectsExamplePolymorphismInterfacesThings to be considered 4/24

5 SWE 316: Software Design and Architecture Object Orientation Real world concepts Software design entities Skljkvjkvjfkavjafkk saovjsdvjfvkfjvkfjk Skljkvjkvjfkavjafkk saovjsdvjfvkfjvkfjk Skljkvjkvjfkavjafkk saovjsdvjfvkfjvkfjk Skljkvjkvjfkavjafkk saovjsdvjfvkfjvkfjk Account getDetails() Transaction execute() Customer getFirstName() Direct correspondence Graphics reproduced with permission from Corel. Object Orientation Classes and ObjectsExamplePolymorphismInterfacesThings to be considered 5/24

6 SWE 316: Software Design and Architecture Benefits of OO Object orientation provides a direct mapping between concepts and code Object Orientation Classes and ObjectsExamplePolymorphismInterfacesThings to be considered 6/24

7 SWE 316: Software Design and Architecture Classes and Objects AjaxCustomer Real worldClass in Design (UML notation) Class in Source code (Java) class AjaxCustomer {.... } PermissionToPay class PermissionToPay {.... } Mental concept Sec 2.2 page 46 Object Orientation Classes and Objects ExamplePolymorphismInterfacesThings to be considered 7/24

8 SWE 316: Software Design and Architecture The Members of a Class Auto public int vehicleID … protected int mileage … private myPrivateVariable … static int numAutosMade … Class model Toyota numAutosMade 12390924850984 aliceBrownBMW:Auto … mileage 33024 jaynesCar:Auto … mileage 83402 Objects of Auto Subclasses have these members too myToyota:Toyota … mileage 2105 … Static variable: One version only Non-static variable: One version for every object Object Orientation Classes and Objects ExamplePolymorphismInterfacesThings to be considered 8/24

9 SWE 316: Software Design and Architecture Attribute Types (Shlaer & Mellor)  Naming:  fixed for each object  distinguishes individuals  Descriptive:  varies through life of object  Referential:  ties instance of one class to instance(s) of another  == aggregation Auto vehicleID mileage owner Object Orientation Classes and Objects ExamplePolymorphismInterfacesThings to be considered 9/24

10 SWE 316: Software Design and Architecture Classes and Objects  A class expresses a concept such as “HondaCivic.”  An object is an instance of a class such as “the Honda Civic with vehicle ID 89R783HJD894.” Object Orientation Classes and Objects ExamplePolymorphismInterfacesThings to be considered 10/24

11 SWE 316: Software Design and Architecture The Clients of a Class class Customer {... String getName() { … } int computeBalance() { … }... } class AjaxWebsiteGenerator {... void makeProfile( Customer c ) { … String name = c.getName() … }... } class AjaxAssets {... int computeAssets() {... Customer c = customers[ i ]; assets += c.computeBalance();... }... } Client of Customer Object Orientation Classes and Objects ExamplePolymorphismInterfacesThings to be considered 11/24

12 SWE 316: Software Design and Architecture Why OO is Useful for Application Development?  Class (Sec 2.2.1)  basic motive of Object Orientation  identifying parts that corresponds to the real world  Instantiation (Sec 2.2.2)  creating instances of encapsulated concepts  Inheritance (Sec 2.3.1)  capturing the way concepts occur in hierarchy  Polymorphism (Sec 2.3.2)  capturing use of single action word to represent different things, depending on context Object Orientation Classes and Objects ExamplePolymorphismInterfacesThings to be considered 12/24

13 SWE 316: Software Design and Architecture Requirements For e-Mail Creation Example 1. Summary: Produces e-mail text for various types of customers. 2. Detailed requirements 2.1 The application displays choices to the console, as shown in figure 2.13. 2.2 For customers delinquent more than 90 days, the e- mail message generated is the statement shown in figure 2.12. Page 1 of 4 Object OrientationClasses and Objects Example PolymorphismInterfacesThings to be considered 13/24

14 SWE 316: Software Design and Architecture Requirements For e-Mail Creation Example 2.3 All non-delinquent customers receive a tailored e-mail messages as follows. 2.3.1 Mountain customers: This month we have a special on West Face tents. Only $700.... lots more output specialized to mountaineering customers... 2.3.2 Regular customers: All items are marked down 20% for this month only.... lots more output for regular customers... Page 3 of 4 Object OrientationClasses and Objects Example PolymorphismInterfacesThings to be considered 14/24

15 SWE 316: Software Design and Architecture Requirements For e-Mail Creation Example 2.4 The e-mail is to be displayed on the console. 3. Future enhancements We anticipate that the text is likely to change frequently, and that new kinds of customers are likely to be specified, each with its own new set of requirements. Page 4 of 4 Object OrientationClasses and Objects Example PolymorphismInterfacesThings to be considered 15/24

16 SWE 316: Software Design and Architecture Disadvantages of Branching  Code for each case not cohesive (“cohesive”: forms a comprehensible unity)  All types of customers coded together in single class Expensive to …  … add new functionality  bloat switch or if - then code  … remove functionality  hunt for all parts that must be removed  … change functionality  hunt for all parts that must be changed Object OrientationClasses and Objects Example PolymorphismInterfacesThings to be considered 16/24

17 SWE 316: Software Design and Architecture Aspects of the Customer Design Needing Improvement  We need to visualize the design  Code not an effective way to understand design  The design’s maintainability still has flaws  As the application grows, specialized class(es) will be required to interact with the user Object OrientationClasses and Objects Example PolymorphismInterfacesThings to be considered 17/24

18 SWE 316: Software Design and Architecture What’s Needed to Specify Functionality  Name of the function Example: add  Argument types(if any) Example:  First parameter: integer  Second parameter: float  Return type Example: double, reference type, void  Exceptions (if any) Example: IOException  More(?)  Are parameters inputs and/or outputs?  Describe what the function does (natural language) Object OrientationClasses and Objects Example PolymorphismInterfacesThings to be considered 18/24

19 SWE 316: Software Design and Architecture Polymorphism  the use of several versions of a method, one in each derived class.  This enables objectOfBaseClass.theMethod() to be interpreted variously at runtime, depending on what derived class objectOfBaseClass belongs to. Object OrientationClasses and ObjectsExample Polymorphism InterfacesThings to be considered 19/24

20 SWE 316: Software Design and Architecture The Need For Interfaces: Simplify … class Draw { … int setColor( String ) { … } Pen getStandardPen() { … } int getLogoStyle() { … } void setColor( int ) { … } void drawLogo( int, int ) { … } void speedUpPen( int ) { … } … } Object OrientationClasses and ObjectsExamplePolymorphism Interfaces Things to be considered 20/24

21 SWE 316: Software Design and Architecture Interface Example: a Draw Class  Functions dealing with the pen used  Pen getStandardPen()  void speedUpPen( int ) ...  Functions dealing with the colors available  void setColor( int )  int setColor( String ) ...  Functions covering the drawing of the company’s logo  void drawLogo( int, int )  int getLogoStyle() ... } } } Pen interface Color interface Logo interface Object OrientationClasses and ObjectsExamplePolymorphism Interfaces Things to be considered 21/24

22 SWE 316: Software Design and Architecture Interfaces An interface is a set of function prototypes (each with name, parameter types, return type, exception type). Object OrientationClasses and ObjectsExamplePolymorphism Interfaces Things to be considered 22/24

23 SWE 316: Software Design and Architecture Issues to be Addressed  How do we visualize a set of classes?  How can classes relate to each other?  How should classes relate to each other?  How can we describe functionality occurring among several classes?  How do we describe the manner in which objects respond to events occurring on them?  Are there patterns of class usage that recur?  So we can existing reuse design parts Object OrientationClasses and ObjectsExamplePolymorphismInterfaces Things to be considered 23/24

24 SWE 316: Software Design and Architecture Summary of This Chapter  A Class represents a concept  Example: House  An Object is an instance of a class  Example: 23 Main Street, Springfield  Classes can relate in several ways: Mainly …  A Client of a class refers to that class in one of its methods  Inheritance: “kind of” relationship  Aggregation: “has a” relationship, explained in chapter xx  Polymorphism means “action depends on context”  Executing anObject.aMethod() actually executes the version of aMethod() in the subclass that anObject belongs to Object OrientationClasses and ObjectsExamplePolymorphismInterfacesThings to be considered 24/24


Download ppt "SWE 316: Software Design and Architecture Objectives Lecture 3 Object Orientation SWE 316: Software Design and Architecture NOTE: most slides are adapted."

Similar presentations


Ads by Google