Lecture 8.2 Aggregation and Inheritance. © 2006 Pearson Addison-Wesley. All rights reserved 8.2.2 Designing with Aggregation and Inheritance Software.

Slides:



Advertisements
Similar presentations
Web Design & Development Lecture 19. Java Graphics 2.
Advertisements

Lecture 10.2 Different Types of Loops, including for and do.
CIS 234: Inheritance Dr. Ralph D. Westfall April, 2010.
(C) 2010 Pearson Education, Inc. All rights reserved. Java™ How to Program, 8/e.
Java™ How to Program, 9/e Presented by: Dr. José M. Reyes Álamo © Copyright by Pearson Education, Inc. All Rights Reserved.
© 2006 Pearson Addison-Wesley. All rights reserved9 A-1 Chapter 9 Advanced Java Topics (inheritance review + Java generics)
© 2006 Pearson Addison-Wesley. All rights reserved9 A-1 Chapter 9 Advanced Java Topics.
Slides prepared by Rose Williams, Binghamton University Chapter 7 Inheritance.
Encapsulation, Inheritance & Interfaces CSE 115 Spring 2006 February 27, March 1 & 3, 2006.
Chapter 2 Application Layer. Copyright © 2005 Pearson Addison-Wesley. All rights reserved. 2-2.
CSCI 143 OOP – Inheritance 1. What is Inheritance? A form of software reuse Create a new class from an existing class – Absorb existing class data and.
Chapter 6 Human Capital. Copyright © 2005 Pearson Addison-Wesley. All rights reserved. 6-2.
©2013 Cengage Learning. All Rights Reserved. Business Management, 13e Managing the Form of Business Ownership Entrepreneurs and Proprietorships.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter N - 1 Chapter 13 Polymorphism is-a relationships Interfaces.
Inheritance Review/Recap. ClassA extends ClassB ClassA now inherits (can access and use) all public and protected elements of ClassB We can expect the.
Chapter 16 Resources and the Environment at the Global Level.
Modelling classes Drawing a Class Diagram. Class diagram First pick the classes –Choose relevant nouns, which have attributes and operations. Find the.
© 2006 Pearson Addison-Wesley. All rights reserved9 A-1 Chapter 9 Advanced Java Topics CS102 Sections 51 and 52 Marc Smith and Jim Ten Eyck Spring 2007.
Chapter 10: Inheritance 1. Inheritance  Inheritance allows a software developer to derive a new class from an existing one  The existing class is called.
(c) University of Washington03-1 CSC 143 Java Inheritance Reading: Ch. 10.
Sadegh Aliakbary Sharif University of Technology Fall 2010.
1 Java Inheritance. 2 Inheritance On the surface, inheritance is a code re-use issue. –we can extend code that is already written in a manageable manner.
Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 11 Inheritance.
© 2006 Pearson Addison-Wesley. All rights reserved Inheritance Systems Merchandise ElectronicsClothing TelevisionCamcorderShirtDressShoe DigitalAnalog.
Specialization and Inheritance Chapter 8. 8 Specialization Specialized classes inherit the properties and methods of the parent or base class. A dog is.
What is inheritance? It is the ability to create a new class from an existing class.
1 Given the Radio class  We may define other derivative types: Cassette walkman IS-A radio Alarm clock radio IS-A radio Car radio IS-A radio.
Object-Oriented Software Development F Software Development Process F Analyze Relationships Among Objects F Class Development F Class Design Guidelines.
Chris Kiekintveld CS 2401 (Fall 2010) Elementary Data Structures and Algorithms Inheritance and Polymorphism.
© 2011 Pearson Education 1 Chapter 13 (Online): Object-Oriented Databases Modern Database Management 10 th Edition, International Edition Jeffrey A. Hoffer,
Domain Modeling Part2: Domain Class Diagram Chapter 4 pp part 2 1.
Lecture 8.3 The Use of JComponent. © 2006 Pearson Addison-Wesley. All rights reserved More About the Standard Drawing Classes java.awt.Container.
Structured Programming Good for programming in the small Often doesn't scale up Limitations –Changes at top may affect lower-level algorithms –Code reuse.
Lecture 8.5 Animating with EventTimer. © 2006 Pearson Addison-Wesley. All rights reserved A Crash Course in the Use of Timed Events What kinds of.
Copyright (c) 1998, 1999 D.L. Bailey * Winter 1999 Part 6 Reusing Classes: Inheritance and Composition.
CSCI-383 Object-Oriented Programming & Design Lecture 10.
Inheritance Inheritance allows a programmer to derive a new class from an existing one The existing class is called the super class, or parent class,
Class Relationships A class defines a type of data Composition allows an object of another class to define an attribute of a class –Employee “has a”
CSE 219 Computer Science III UML. UML Diagrams UML - Unified Modeling Language UML diagrams are used to design object-oriented software systems –represent.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 11 Object-Oriented.
Inheritance CSI 1101 Nour El Kadri. OOP  We have seen that object-oriented programming (OOP) helps organizing and maintaining large software systems.
CSE 143 Lecture 12 Inheritance slides created by Ethan Apter
Csci 490 / Engr 596 Special Topics / Special Projects Software Design and Scala Programming Spring Semester 2010 Lecture Notes.
29-July-2002cse Inheritance © 2002 University of Washington1 Inheritance CSE 142, Summer 2002 Computer Programming 1
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Object-Oriented Design.
© Copyright 2012 by Pearson Education, Inc. All Rights Reserved. Chapter 12 Inheritance and Class Design 1.
AP Computer Science A – Healdsburg High School 1 Inheritance - What is inheritance? - “Is-a” vs. “Has-a” relationship - Programming example “CircleBug”
Copyright 2010 by Pearson Education Building Java Programs Chapter 9 Lecture 9-1: Inheritance reading: 9.1.
Inheritance vs Composition Picking the right tool.
© 2006 Pearson Addison-Wesley. All rights reserved Non-void Methods Parameters are largely one-way communication.  Shared instances variables is.
Extended ER Modelling. Extended E-R Features: Specialization Top-down design process; we designate subgroupings within an entity set that are distinctive.
CS 116 Object Oriented Programming II Lecture 9 Acknowledgement: Contains materials provided by George Koutsogiannakis and Matt Bauer.
SUBCLASSES - JAVA. The Purpose of Subclasses Class Farm String getOwner() void setOwner(String s) int getSize() void setSize(int s) Class DairyFarm String.
1 Inheritance One of the goals of object oriented programming is code reuse. Inheritance is one mechanism for accomplishing code reuse. It allows us to.
CSE 143 Lecture 13 Inheritance slides created by Ethan Apter
Inheritance Class Hierarchies SoftUni Team Technical Trainers Software University
Aggregation and Inheritance
Inheritance ITI1121 Nour El Kadri.
Python First Edition STARTING OUT WITH Chapter 10 Inheritance
Interface, Subclass, and Abstract Class Review
public class Doubler extends Base {
An Introduction to Inheritance
Pre-AP® Computer Science Quiz Key
Pre-AP® Computer Science Quiz
Understand and Use Object Oriented Methods
Class Hierarchies and Type Conformance
PreAP Computer Science Quiz
Extending Classes Through Inheritance
ADVANCED OBJECT-ORIENTED PROGRAMMING
Chapter 7 Inheritance.
Presentation transcript:

Lecture 8.2 Aggregation and Inheritance

© 2006 Pearson Addison-Wesley. All rights reserved Designing with Aggregation and Inheritance Software Design Step 1 Identify the objects. Step 2 Find/design a class for each object. One of the Challenges deciding when to use aggregation and when to use inheritance SupplierClass ClientClass SuperClass SubClass

© 2006 Pearson Addison-Wesley. All rights reserved What is AGGREGATION? public class SomeAggregate { private ClassA partA; private ClassB partB; private ClassC partC1; private ClassC partC2; // methods omitted } public class SomeAggregate { private ClassA partA; private ClassB partB; private ClassC partC1; private ClassC partC2; // methods omitted } SomeAggregate ClassAClassBClassC

© 2006 Pearson Addison-Wesley. All rights reserved Class Diagram public class SomeAggregate { private ClassA partA; private ClassB partB; private ClassC partC1; private ClassC partC2; // methods omitted } public class SomeAggregate { private ClassA partA; private ClassB partB; private ClassC partC1; private ClassC partC2; // methods omitted } SomeAggregate ClassAClassBClassC Object Diagram :SomeAggregate partA : ClassA partB : ClassBpartC1 : ClassC partC2 : ClassC

© 2006 Pearson Addison-Wesley. All rights reserved When to aggregate? One class contains_a other. A dog has_a tail. An equilateral triangle contains_a vertex. A sandal includes_a sole. A company’s work roster contains_an employee. Cherry pie contains_a cherry pit. contains_a

© 2006 Pearson Addison-Wesley. All rights reserved When to inherit? One class is_a another class A dog is_an animal. An equilateral triangle is_a triangle. A sandal is_a special kind of footware. An hourly employee is_an employee. Cherry pie is_a dessert. is_a Generalizations can be discovered from common attributes.

© 2006 Pearson Addison-Wesley. All rights reserved Create the best relationship from... camcorder record button tape recorder lens on/off switch viewfinder tape recordercamcorderrecord buttonon/off switchlensviewfinder

© 2006 Pearson Addison-Wesley. All rights reserved A Dilemma (which is it?) A Camcorder is_a tape recorder. or A Camcorder contains_a tape recorder. Either aggregation or inheritance will work in this case (see next slide).

© 2006 Pearson Addison-Wesley. All rights reserved public class Camcorder { private TapeRecorder rec; //somewhere in the code rec.startRecording(); } public class Camcorder { private TapeRecorder rec; //somewhere in the code rec.startRecording(); } public class Camcorder extends TapeRecorder { //somewhere in the code startRecording(); } public class Camcorder extends TapeRecorder { //somewhere in the code startRecording(); }

© 2006 Pearson Addison-Wesley. All rights reserved java.awt.Container Container is an awt class well suited to inheritance. An Container subclass can reuse...  add and remove  setBounds and setLocation  getX, getY, getWidth, getHeight, getBackground  repaint A Container subclass may want to override...  setSize and setBounds  setBackground A Container object is a transparent rectangle. It is useful for grouping other graphical objects into a single unit.