Presentation is loading. Please wait.

Presentation is loading. Please wait.

Gayle J Yaverbaum School of Business Administration Penn State Harrisburg Fall 2006 Object-Oriented Design and Program Development in Business INFSY 535.1.

Similar presentations


Presentation on theme: "Gayle J Yaverbaum School of Business Administration Penn State Harrisburg Fall 2006 Object-Oriented Design and Program Development in Business INFSY 535.1."— Presentation transcript:

1 Gayle J Yaverbaum School of Business Administration Penn State Harrisburg Fall 2006 Object-Oriented Design and Program Development in Business INFSY 535.1

2 UML Diagram for a Words Hierarchy Book # pages : int + pageMessage() : void Dictionary - definitions : int + definitionMessage() : void Review and Quiz!

3 Terminology constructor method signature mutator and accessor method (accessor non quiz but better answer) overloading/polymorphism local variable(s) instance variable (not on quiz) group of related classes scope

4

5 ServiceBusinessRetailBusiness Business ancestor descendents Right LegLeft Leg Leg whole parts Generalization: is-a relationship Aggregation: composition relationship

6 CageBowl Iquana Association (has-a) Author breaks relationships into two parts: 1) containment diagram 2) inheritance and association diagram

7 Iguana - _color:Color -_leftBackLeg, _rightBackLeg: Leg - _foodDish: Bowl - _cage:Cage + Iguana + move(): void + eat (): void cage bowl Leg 1 1…* 4 Iquana Example UML attribute Leg is a component object Iguana is the container object containing the parts associations May create multiple instances

8

9 Business KMartMacys ServiceBusiness Kinkos RetailBusiness The child inherits characteristics of the parent: (both methods and data) Note: Single inheritance in JAVA is-a

10 package firstapp; import wheels.users.*; /* * Chapter 1: FirstApp.java * Displays a red circle on a white background. * The keyword extends is is-a relationship or a generalization. /* public class FirstApp extends wheels.users.Frame { private wheels.users.Ellipse _ellipse; public FirstApp () { _ellipse = new wheels.users.Ellipse(); } public static void main(String[] args) { FirstApp app = new FirstApp(); }

11 Deriving Subclasses JAVA Example 1: class FirstApp extends Frame Words.java, Book.java, Dictionary.java Example 2: class Dictionary extends Book { }

12 The protected Modifier Visibility modifiers: determine which class members are inherited and which are not  + +  - public variables violate the principle of encapsulation WHY? Another modifier: # Variable and methods declared with protected (Inherited by the derived class)

13 Overriding inherited methods  a method with the same name and signature as that in the parent method.  super. refers to the method in the parent class.

14 Prepare for Analysis of the Blob App Program Download the following files: –http://www.personal.psu.edu/gjy1/infsy535/blo bapp/Blob.javahttp://www.personal.psu.edu/gjy1/infsy535/blo bapp/Blob.java –http://www.personal.psu.edu/gjy1/infsy535/blo bapp/WinkingBlob.javahttp://www.personal.psu.edu/gjy1/infsy535/blo bapp/WinkingBlob.java –http://www.personal.psu.edu/gjy1/infsy535/blo bapp/BlobApp.javahttp://www.personal.psu.edu/gjy1/infsy535/blo bapp/BlobApp.java –http://www.personal.psu.edu/gjy1/infsy535/blo bapp/TalkativeBlob.javahttp://www.personal.psu.edu/gjy1/infsy535/blo bapp/TalkativeBlob.java

15 Prepare for Analysis of the Blob App Program Set up a “blobapp package” and place files in Eclipse Add wheels to the project Run the package!

16 package blobapp; import wheels.users.*; public class BlobApp extends Frame { private WinkingBlob _winky; private TalkativeBlob _talky; public BlobApp() { super(x, y); _winky = new WingingBlob (300,300); _talky = new TalkativeBlob (400,200, “I’m so happy”); System.out.println (" Sample print debugging); } public static void main (String[] argv) { new BlobApp(); } BlopApp (implementation) Text: Chapter 3 Creates the frame Instantiation: Components of BlobApp

17 Blob WinkingBlobTalkativeBlob BlobApp UML Diagram (note together rather than separate as in text, pp 116) Container object WinkingBlob is a component of BlobApp Is-a Blob

18 package blobapp; import wheels.users.*; public class WinkingBlob extends Blob { public WinkingBlob (int x, int y) { super(x, y); } public void mousePressed(java.awt.event.MouseEvent e){ super.mousePressed(e); _leftEye.setSize(30, 5); _leftEye.setLocation(_leftEye.getLocation().x, _leftEye.getLocation().y+15); } public void mouseReleased(java.awt.event.MouseEvent e){ super.mouseReleased(e); _leftEye.setSize(30, 30); _leftEye.setLocation(_leftEye.getLocation().x, _leftEye.getLocation().y-15); } is-a X and y passed as ellipse dimensions and super refers to Blob

19 package blobapp; import wheels.users.*; public class TalkativeBlob extends Blob { ConversationBubble _bubble; public TalkativeBlob(int x, int y, String speech) { super (x, y); _bubble = new ConversationBubble (speech); _bubble.setLocation(x-100, y-100); _bubble.hide(); } public void mousePressed(java.awt.event.MouseEvent e){ _bubble.show(); } public void mouseReleased(java.awt.event.MouseEvent e){ _bubble.hide(); } Blob extends Ellipse

20 package blobapp; import wheels.users.*; public class Blob extends Ellipse { protected Ellipse _leftEye, _rightEye; public Blob(int x, int y) { super(x, y); this.setSize(100, 100); _leftEye = new Ellipse(java.awt.Color.black); _rightEye = new Ellipse(java.awt.Color.black); _leftEye.setSize(30, 30); _rightEye.setSize(30, 30); _leftEye.setLocation(this.getLocation().x+22, this.getLocation().y+10); _rightEye.setLocation(this.getLocation().x+47, this.getLocation().y+10); } public void mousePressed(java.awt.event.MouseEvent e){ this.setFillColor(java.awt.Color.blue); } public void mouseReleased(java.awt.event.MouseEvent e){ this.setFillColor(java.awt.Color.red); } } Each ellipse instantiation


Download ppt "Gayle J Yaverbaum School of Business Administration Penn State Harrisburg Fall 2006 Object-Oriented Design and Program Development in Business INFSY 535.1."

Similar presentations


Ads by Google