Download presentation
Presentation is loading. Please wait.
Published byDoreen Kennedy Modified over 9 years ago
1
Chapter 2 Object Orientation
2
Process Phase Affected by This Chapter Requirements Analysis Design Implementation ArchitectureFrameworkDetailed Design Key:= less so Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.
3
Before Object Orientation Real world concepts Software Design Entities Skljkvjkvjfkavjafkk saovjsdvjfvkfjvkfjk Skljkvjkvjfkavjafkk saovjsdvjfvkfjvkfjk Skljkvjkvjfkavjafkk saovjsdvjfvkfjvkfjk Skljkvjkvjfkavjafkk saovjsdvjfvkfjvkfjk Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.
4
How Do We Express Ourselves? "Customers Montague and Susan entered the Ajax bank and were served by teller Andy..... " AJAX BANK Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.
5
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. Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.
6
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. Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.
7
Key Concept: Benefits of OO Object orientation provides a direct mapping between concepts and code. Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.
8
Class Introduction AjaxCustomer Real worldClass in Design (UML notation) Class in Source code (Java) class AjaxCustomer {.... } PermissionToPay class PermissionToPay {.... } Mental concept Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.
9
aliceBrownBMW:Auto … The Members of a Class Auto public int vehicleID … protected int mileage … private myPrivateVariable … static int numAutosMade … Class model Toyota numAutosMade 12390924850984 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 Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.
10
Attribute Types (Shlaer & Mellor) o Naming: o fixed for each object o distinguishes individuals o Descriptive: o varies through life of object o Referential: o ties instance of one class to instance(s) of another o == aggregation Auto vehicleID mileage owner Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.
11
Key Concept: 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.”
12
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 Class Customer Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.
13
Aspects of OO Useful for Application Development Class Introduction (section 2.2.1) o basic motive of Object Orientation o identifying parts that corresponds to the real world Instantiation (section 2.2.2) o creating instances of encapsulated concepts Inheritance (section 2.3.1) o capturing the way concepts occur in hierarchy Polymorphism (section 2.3.2) o capturing use of single action word to represent different things, depending on context Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.
14
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 xx. 2.2 For customers delinquent more than 90 days, the e-mail message generated is the statement shown in figure xx. Page 1 of 4 Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.
15
Typical Interaction for e-mail Creation Example Page 2 of 4 Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.
16
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... Requirements For e-Mail Creation Example Page 3 of 4 Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.
17
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 Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.
18
Disadvantages of Branching o Code for each case not cohesive (“cohesive”: forms a comprehensible unity) o All types of customers coded together in single class Expensive to … o … add new functionality o bloat switch or if - then code o … remove functionality o hunt for all parts that must be removed o … change functionality o hunt for all parts that must be changed Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.
19
Aspects of the Customer Design Needing Improvement o We need to visualize the design o Code not an effective way to understand design o The design’s maintainability still has flaws o As the application grows, specialized class(es) will be required to interact with the user Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.
20
Key Concept: 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. Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.
21
What’s Needed to Specify Functionality o Name of the function Example: add o Argument types(if any) Example: o First parameter: integer o Second parameter: float o Return type Example: double, reference type, void o Exceptions (if any) Example: IOException o More(?) o Are parameters inputs and/or outputs? o Describe what the function does (natural language) Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.
22
The Need For Interfaces: Simplify … class Draw { … int setColor( String ) { … } Pen getStandardPen() { … } int getLogoStyle() { … } void setColor( int ) { … } void drawLogo( int, int ) { … } void speedUpPen( int ) { … } … }
23
Interface Example: a Draw Class o Functions dealing with the pen used o Pen getStandardPen() o void speedUpPen( int ) o... o Functions dealing with the colors available o void setColor( int ) o int setColor( String ) o... o Functions covering the drawing of the company’s logo o void drawLogo( int, int ) o int getLogoStyle() o... o....... } } } Pen interface Color interface Logo interface Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.
24
Key Concept: Interfaces An interface is a set of function prototypes (each with name, parameter types, return type, exception type). Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.
25
Issues to be Addressed o How do we visualize a set of classes? o How can classes relate to each other? o How should classes relate to each other? o How can we describe functionality occurring among several classes? o How do we describe the manner in which objects respond to events occurring on them? o Are there patterns of class usage that recur? o So we can existing design parts Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.
26
Summary of This Chapter o A Class represents a concept o Example: House o An Object is an instance of a class o Example: 23 Main Street, Springfield o Classes can relate in several ways: Mainly … o A Client of a class refers to that class in one of its methods o Inheritance: “kind of” relationship o Aggregation: “has a” relationship, explained in chapter xx o Polymorphism means “action depends on context” o Executing anObject.aMethod() actually executes the version of aMethod() in the subclass that anObject belongs to Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.
27
Typical Interaction for Auto Description Exercise Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.