Concepts 6. OOAD Part II. BlueJ ex 5.1. OO and inheritance. Intro to inheritance. The DoME project is a database for multimedia entertainment.

Similar documents
Further abstraction techniques

Further abstraction techniques

Chapter 8: Class and Method Design

11 Further abstraction techniques

Objects First with Java

CS250 Intro to CS II. Spring CS250 - Intro to CS II 1

Foundations of object orientation

Data Structures and Algorithms Design Goals Implementation Goals Design Principles Design Techniques. Version 03.s 2-1

Object Oriented Programming in Java. Jaanus Pöial, PhD Tallinn, Estonia

CMSC 132: Object-Oriented Programming II

Chapter 10 Classes Continued. Fundamentals of Java

OOAD - OBJECT MODEL. The concepts of objects and classes are intrinsically linked with each other and form the foundation of object oriented paradigm.

Object Oriented Programming. Java-Lecture 11 Polymorphism

Inheritance and Polymorphism

Improving structure with inheritance

Main concepts to be covered. Simulations. Simulations. Simulations (not real world) Benefits of simulations

Abstract Classes. Abstract Classes a and Interfaces. Class Shape Hierarchy. Problem AND Requirements. Abstract Classes.

Programming II (CS300)

CS111: PROGRAMMING LANGUAGE II

CMSC 132: Object-Oriented Programming II

Contents. I. Classes, Superclasses, and Subclasses. Topic 04 - Inheritance

IT101. Inheritance, Encapsulation, Polymorphism and Constructors

Java Object Oriented Design. CSC207 Fall 2014

Improving structure with inheritance. Main concepts to be covered. The DoME example. DoME objects. DoME classes. DoME object model

Programming II (CS300)

Object Orientated Analysis and Design. Benjamin Kenwright

Object-Oriented Design

Polymorphism. Object Orientated Programming in Java. Benjamin Kenwright

[ L5P1] Object-Oriented Programming: Advanced Concepts

Polymorphism. Arizona State University 1

Software Paradigms (Lesson 3) Object-Oriented Paradigm (2)

Object Oriented Concepts. Produced by. Introduction to the Java Programming Language. Eamonn de Leastar

Relationships Between Real Things. CSE 143 Java. Common Relationship Patterns. Composition: "has a" CSE143 Sp Student.

Object Oriented Programming: Based on slides from Skrien Chapter 2

Relationships Between Real Things CSC 143. Common Relationship Patterns. Composition: "has a" CSC Employee. Supervisor

More on Objects in JAVA TM

Lecture 13: Object orientation. Object oriented programming. Introduction. Object oriented programming. OO and ADT:s. Introduction

OBJECT ORIENTED SYSTEM DEVELOPMENT Software Development Dynamic System Development Information system solution Steps in System Development Analysis

Outline. Subtype Polymorphism, Subtyping vs. Subclassing, Liskov Substitution Principle. Benefits of Subtype Polymorphism. Subtype Polymorphism

Inheritance -- Introduction

Object-Oriented Languages and Object-Oriented Design. Ghezzi&Jazayeri: OO Languages 1

SDC Design patterns GoF

1: Introduction to Object (1)

2. Classes & Inheritance. Classes. Classes. Éric Tanter Objects and Design in Smalltalk. How do you create objects?

Announcement. Agenda 7/31/2008. Polymorphism, Dynamic Binding and Interface. The class will continue on Tuesday, 12 th August

OBJECT ORİENTATİON ENCAPSULATİON

Object-Oriented Design

Exam Questions. Object-Oriented Design, IV1350. Maximum exam score is 100, grade limits are as follows. Score Grade 90 A 80 B 70 C 60 D 50 E

Object modeling and geodatabases. GEOG 419: Advanced GIS

What about Object-Oriented Languages?

CS 520 Theory and Practice of Software Engineering Fall 2018

SOFTWARE DESIGN COSC 4353 / Dr. Raj Singh

Relationships Between Real Things CSE 143. Common Relationship Patterns. Employee. Supervisor

Chapter 6 Introduction to Defining Classes

OVERRIDING. 7/11/2015 Budditha Hettige 82

Designing applications. Main concepts to be covered

Programming in C++ Prof. Partha Pratim Das Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur

Object-Oriented Concepts and Design Principles

Basic Object-Orientation

Chapter 11 Classes Continued

Objectives. INHERITANCE - Part 1. Using inheritance to promote software reusability. OOP Major Capabilities. When using Inheritance?

Inheritance. A key OOP concept

INHERITANCE - Part 1. CSC 330 OO Software Design 1

Inheritance & Polymorphism Recap. Inheritance & Polymorphism 1

Abstraction. Design fundamentals in OO Systems. Fundamental Software Development Principles

CS111: PROGRAMMING LANGUAGE II

CS 520 Theory and Practice of Software Engineering Fall 2017

What s Conformance? Conformance. Conformance and Class Invariants Question: Conformance and Overriding

Object Oriented Features. Inheritance. Inheritance. CS257 Computer Science I Kevin Sahr, PhD. Lecture 10: Inheritance

Software Service Engineering

Chapter 5 Object-Oriented Programming

HAS-A Relationship. Association is a relationship where all objects have their own lifecycle and there is no owner.

CSSE 220 Day 15. Inheritance. Check out DiscountSubclasses from SVN

More About Objects. Zheng-Liang Lu Java Programming 255 / 282

1. Write two major differences between Object-oriented programming and procedural programming?

Introduction to Inheritance

Module Outline. What is Object-Oriented? Some Possible Definitions. Why Object-oriented? Fundamentals of Object Orientation

Introduction to C++ Introduction to C++ Dr Alex Martin 2013 Slide 1

Introduction to Object- Oriented Programming

Java How to Program, 8/e

Logistics. Final Exam on Friday at 3pm in CHEM 102

Software Development

Object- Oriented Design with UML and Java Part I: Fundamentals

UNIT 3 ARRAYS, RECURSION, AND COMPLEXITY CHAPTER 11 CLASSES CONTINUED

C++ Important Questions with Answers

UML & OO FUNDAMENTALS CSCI 4448/5448: OBJECT-ORIENTED ANALYSIS & DESIGN LECTURE 3 08/30/2011

What are the characteristics of Object Oriented programming language?

Unified Modeling Language (UML) Class Diagram

Design Pattern and Software Architecture: IV. Design Pattern

Inheritance, Polymorphism, and Interfaces

REVIEW OF THE BASIC CHARACTERISTICS OF OBJECT ORIENTATION

Object-Oriented Design

An Introduction to Object Orientation

1Z0-808 oracle. Number: 1Z0-808 Passing Score: 800 Time Limit: 120 min.

Unified Modeling Language (UML) and Modeling

OO System Models Static Views

Lab 2: Object-Oriented Design 12:00 PM, Jan 31, 2018

Appendix A - Glossary(of OO software term s)

n HW5 out, due Tuesday October 30 th n Part 1: Questions on material we ll cover today n Part 2: BFS using your graph from HW4

Data Abstraction. Hwansoo Han

Transcription:

Concepts 6 Generalization A relation between a general and a specialized element. The more special adds further properties. Inheritance A relation between a VXSHUFODVV and a VXEFODVV. Subclasses share properties of their superclasses. OOAD Part II Intro to inheritance BlueJ ex 5.1 The DoME project is a database for multimedia entertainment. Open DoME-v1. Draw class diagram. (Aggregate or composite?) Discuss extension with DVDs (etc.) OO and inheritance So far, we have discussed OO principles that are relatively easy to support also in non OO languages such as C, F77, etc. Now, we continue with inheritance, a key feature of OO. Not supported in non OO languages. NB: OOAD may still be used for designing, but implementation of OOAD is easier in OO languages.

BlueJ ex 5.3 Open DoME-v3. What is the difference between v2 and v3? Is the polymorphism useful here? Discuss extension with DVDs. BlueJ ex 5.2 Open DoME-v2. Draw class diagram. Discuss extension with DVD. Has anything been gained so far? Has anything been lost? Concepts 8 Concepts 7 Protected visibility may be specified for features in a superclass. Protected features are visible to subclasses. Remark: Protected visibility is often useful. However, it should be used with care, since it does violate information hiding. Polymorphism When homonymous messages to compatible objects of different classes may trigger a different behavior. In dynamic polymorphism, a message is assigned to a concrete method not at compile time, but during runtime. Dynamic binding is a prerequisite for dynamic polymorphism. Remark: Two objects of different subclasses to same superclass are compatible. Inheritance is often called the is-a relationship.

OOAD Regarding polymorphism: Usually, it refers to dynamic polymorphism. Sometimes, compile-time (static) polymorphism can be used instead. In the OO analysis, it is not important to distinguish between dynamic and static polymorphism. In the OO design, static polymorphism can (sometimes ) be chosen. This may be important for scientific programs, with high performance demands. BlueJ ex 5.4 Discuss the visibility of all inherited features of an Item. How does protected features of Item affect the Database? On simulations: BlueJ ex 6 intro Computers often used for (scientific) simulations A computer simulation tries to model a subset of the real world. Need to simplify Abstraction LV important. Benefit of simulations: experiments, what if questions, etc. (when real thing is too costly, or dangerous, or ) Example: Environmental simulation: effect of human activity on a habitat. Suppose a freeway thru a national park is planned: Will the animals be affected? OOAD Summary of inheritance so far. Benefits: Avoids code duplication Promotes reuse (beware ) Simplifies maintenance Simplifies extensions Promotes abstraction Note that inheritance is not DOZD\V suitable. Too complex inheritance hierarchies are difficult to understand. For time critical operations, it may degrade performance.

BlueJ ex 1.2, 5.4 Let us revisit the DoME project. Should the Item super class be abstract? Consider adding a Shape super class in the Shapes project. Should the Shape super class be abstract? BlueJ ex 6.1 Open foxes-and-rabbits-v1 project. Play around with it. (Is the simulation realistic?) Draw &5&FDUGV for classes Simulator, Rabbit and Fox. (A CRC card states the class, its responsibilities and its collaborators.) Compare CRC cards with class diagram. When may CRC cards be useful? Illustrate in detail how the associations between Simulator, Rabbit, and Fox is implemented. BlueJ ex 6.2 Of course, an abstract class Animal is appropriate. Discuss its benefits for Fox and Rabbit. Discuss its benefit for Hare. Discuss its benefits for Simulator. Is the dependency on Fox and Rabbit completely removed? What changes do we get in other classes? Concept 9 Abstract class An abstract class is intentionally incomplete; it lacks implementation of some methods. These methods are called abstract methods. No objects can be instantiated of an abstract class. Concrete class is a class which is not abstract. Note that (concrete) subclasses to abstract classes must implement the abstract methods.

OOAD summary part II We have discussed Generalization Inheritance Polymorphism Abstract classes Interfaces Inheritance is a key feature of OO. It is essential for polymorphism. In OOAD, it should model is-a dependencies. Concepts 10 Multiple inheritance is when a subclass inherits (directly) from more than one super class. Interface A class which only specifies abstract methods is an interface. Remarks: Multiple inheritance may cause trouble. The problem is when LPSOHPHQWDWLRQ is multiply inherited. Multiple inheritance of interfaces is OK, though. BlueJ ex 6.3 Discuss a Drawable interface. Consider classes Actor, Animal, Hunter, Fox, Rabbit, and Season. Discuss SimulatorView as a super class to AnimatedView and TextView. What if you want both an animated view and a text view? When do we use abstract classes and when do we use interfaces?