Docsity

Object-Oriented Design - Advanced Programming - Lecture Slides, Slides of Computer Science

Partial preview of the text

Download Object-Oriented Design - Advanced Programming - Lecture Slides and more Slides Computer Science in PDF only on Docsity!

Concepts in Object-Oriented

Design

CSCI 240

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

Objects, Instances of a Class

• Classes define what properties will exist in each

instance

• Objects provide distinct instances that exhibit those

properties

George : Student · (^) Name=“George” · (^) Attendence=100% · (^) Current Grade=A

Lee : Student · (^) Name=“Lee” · (^) Attendence=85% · (^) Current Grade=B

Class Objects

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.

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.

Functionally-Oriented Instructor Take Attendence() { Look at back of each student’s hand!!! }

Object-Oriented Instructor Take Attendence() { Ask each student for their name. }

You're just data to me. Hand it over so I can do my job.

You're an object. You implement something I need. I'll ask you for it.

Messages are passed and handled, rather than invoked like functions. Docsity.com

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

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

Person · (^) Name

Student · (^) Name · (^) Attendence · (^) Current Grade

Comparison of

Functional vs. OO Views

Register

Student

Print Transcript

Submit Grade

Students

Students Grades

Student/Grades

Student

Register( ) Submit Score( ) Print Transcript( )

0..*

Score Name 0..* Value

Addition of a New Student Type

  • Changes in data types cause significant impact to functional approaches
  • OO approaches allow new object types to re-define functionality

Register

Student

Print Transcript

Submit Grade

Students

Students/ Pass Fail Students Grades/PF

Student/Grades/PF

Impact

Areas

Student

Register( ) Submit Score( ) Print Transcript( )

0..*

Score Name 0..* Value

PassFail Student

Print Transcript( ) function override

Re-organization of OO Abstractions

  • Data dependent behavior handled by derived classes
  • New functionality handled by new associated classes ("wrappers", "adapters", "views")

0..*

Score Name Value

Student Register( ) Submit Score( )

0..*

0..

Transcript Print( )

0..

PassFail Student Determine Grade( )

0..*

Score Name Value

0..

Transcript Print( ) Student Register( ) Submit Score( ) Determine Grade( )

0..*

0..

PassFail Student Determine Grade( )

0..*

Score Name Value

0..

Transcript Print( )

0..

Report Card Print( )

Student Register( ) Submit Score( ) Determine Grade( )

0..*

0..

0..

UML Sample Package View

Library Package

Media Borrowers Fines