Concepts in Object-Oriented Design - PowerPoint PPT Presentation

1 / 16
About This Presentation
Title:

Concepts in Object-Oriented Design

Description:

Concepts in Object-Oriented Design. CSCI 240. Dale Roberts, Lecturer ... Example: Classroom. Attending the lecture we have several individuals. Wade ... Abstraction ... – PowerPoint PPT presentation

Number of Views:12
Avg rating:3.0/5.0
Slides: 17
Provided by: dalero
Learn more at: http://cs.iupui.edu
Category:

less

Transcript and Presenter's Notes

Title: Concepts in Object-Oriented Design


1
Concepts in Object-Oriented Design
  • CSCI 240

Dale Roberts, Lecturer Computer Science,
IUPUI E-mail droberts_at_cs.iupui.edu
2
Example Classroom
  • Attending the lecture we have several individuals
  • Wade - loves Chinese food
  • George - an outdoorsman
  • Wendle - is a sports nut
  • Lee - doesn't eat anything with a vowel in its
    name
  • These are the students of our lecture
  • Note that the individuals are not identical.

Wade George
Wendle
Lee
3
Abstraction and Classes
  • From our perspective, we see them as an
    instantiation of a "Class", Student
  • has a name
  • attends class
  • has a grade
  • completes assignments
  • Note the each student looks the same
  • even though the are different individuals
  • A Class defines an "Abstraction"
  • OO Abstractions are based on
  • data (name, grade, attendance record)
  • "Attributes"
  • simple access
  • behavior (completes assignments, attends class)
  • "Operations/Methods"
  • complex properties
  • relationships (student in course)
  • external implementations

4
Objects, Instances of a Class
  • Classes define what properties will exist in each
    instance
  • Objects provide distinct instances that exhibit
    those properties

Class
Objects
George Student


NameGeorge


Attendence100


Current
GradeA
Lee Student


NameLee


Attendence85


Current
Notice that the data members are replicated in
each object. Each object is an instance of
Student. It does not make sense to replicate
member functions.
GradeB
5
Messaging Supports Encapsulation
  • We interact with objects through "messages"
  • Messages allow object to determine implementation
    rather than the sender determining the
    implementation for each instance.

Messages are passed and handled, rather than
invoked like functions.
6
Polymorphism Supports Encapsulation
  • Allows an object of any implementation type,
    which satisfies the interface defined by the
    abstraction, to be used by a generic reference to
    an abstraction.
  • Promotes a separation of interface and
    implementation

class GraduateStudent Student float
calculateScore(Student s) GraduateStudent
George calculateScore(George)
Wade is an undergraduate Student
George is an graduate Student
Polymorphism says that you can treat both Wade
and George as Students if the distinction between
undergraduate and graduate is not important.
7
Hierarchies
  • Organize lower level abstractions into more
    complex abstractions
  • Hierarchies allow more complex abstractions to be
    understood
  • Two basic forms
  • Inheritance
  • Generalization - Specialization
  • Base Class - Derived Class
  • Parent - Child
  • Abstract Class - Concrete Class
  • Aggregation (many-to-one relationships)
  • Whole - Part
  • Containership
  • Collection
  • Group

8
Inheritance Hierarchy
  • an "is-A" relationship
  • Inheritance
  • for type - a re-use of common interface
  • for class - a re-use of common interface and
    implementation

Student
Person


Name


Name


Attendence


Current
Grade
9
Aggregation Hierarchy
  • a "has-A" relationship
  • assembly-part - where the aggregation of parts
    makes up the whole
  • ex airplane is an aggregation of wings, wheels,
    motor, prop, etc.
  • container-contents - where the container exists
    with or without contents
  • ex classroom is an aggregation of students,
    instructor, tables, chairs, etc.
  • group-member - where members are logically
    associated with whole
  • ex course has students and teachers as members
  • "weak has-A" - where there is more of a
    peer-to-peer relationship between abstractions
    (association)
  • ex Instructor has students, Students have
    instructor

10
Comparison of Functional vs. OO Views
Register Student
Submit Grade
Students
Grades
Students
Student/Grades
Print Transcript
11
Addition of a New Student Type
Register Student
Submit Grade
Students/ Pass Fail Students
Grades/PF
Impact Areas
Students
Student/Grades/PF
Print Transcript
function override
  • Changes in data types cause significant impact to
    functional approaches
  • OO approaches allow new object types to re-define
    functionality

12
Addition of New Report Type
Register Student
Submit Grade
Impact Areas
Students
Grades
Students
Student/Grades/PF
Student/Grades/PF
Print Report Card
Print Transcript
  • Changes in functionality based on stable data
    causes significant impact across objects
  • Functional approaches allow new functions to
    augment functionality

13
Re-organization of OO Abstractions
  • Data dependent behavior handled by derived
    classes
  • New functionality handled by new associated
    classes ("wrappers", "adapters", "views")

14
UML Sample Package View
15
UML Sample Class View
Diamond implies composition All MediaTopics
together comprise a CardCatalog.
Notice that this sample class view does not
include visibility indicators.
16
Acknowledgements
  • This presentation is an adaptation of materials
    developed by Jim Stafford, John Hopkins
    University. Used by permission.
Write a Comment
User Comments (0)
About PowerShow.com