Download presentation
Presentation is loading. Please wait.
Published byBeatrice Green Modified over 9 years ago
1
Fundamentals of OO
2
CSCI 265Dale Roberts 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 Wade GeorgeWendle Lee
3
CSCI 265Dale Roberts 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 A Class defines an "Abstraction" OO Abstractions are based on –data (name, attendance) "Attributes" simple access –behavior (completes assignments, attends class) "Operations/Methods" complex properties –relationships (student in course) external implementations
4
CSCI 265Dale Roberts Objects, Instances of a Class Classes define what properties will exist 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.
5
CSCI 265Dale Roberts Encapsulation and Objects Classes form the interface for interaction, Objects provide the implementation –they are instances of a class (student) –they have unique behavior –they have state Student · GetName() ClassObjects
6
CSCI 265Dale Roberts 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
7
CSCI 265Dale Roberts 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 float calculate Score(Student s); GraduateStudent Wade; calculateScore(Wade)
8
CSCI 265Dale Roberts 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 Whole - Part Containership Collection Group
9
CSCI 265Dale Roberts 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
10
CSCI 265Dale Roberts 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
11
CSCI 265Dale Roberts Summary of Object-Oriented Concepts Abstraction –Class –Attribute –Behavior –Relations –Encapsulation Object –Message –Polymorphism Hierarchies –Inheritance –Aggregation “Is-A” relationships are implemented through inheritance. “Has-A” relationships are implemented through data members. Data structures are used to implement the various “Has-A” relationships. For example, multiple children are maintained through container data structures such as arrays and linked lists.
12
CSCI 265Dale Roberts Comparison of Functional vs. OO Views Register Student Print Transcript Submit Grade Students Grades Student/Grades
13
CSCI 265Dale Roberts 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 function override
14
CSCI 265Dale Roberts Addition of New Report Type Changes in functionality based on stable data causes significant impact across objects Functional approaches allow new functions to augment functionality Print Transcript Submit Grade Students Grades Student/Grades/PF Register Student Print Report Card Student/Grades/PF Impact Areas
15
CSCI 265Dale Roberts Re-organization of OO Abstractions Data dependent behavior handled by derived classes New functionality handled by new associated classes ("wrappers", "adapters", "views")
16
CSCI 265Dale Roberts Exercise: Identifying OO Properties Provide examples of the following concepts using an Answering Machine. –Class: –Attribute: –Behavior: –Object: –Association: –Inheritance: –Aggregation:
17
CSCI 265Dale Roberts Provide examples of the following concepts using a domain you are familiar with. Prepare your results on a transparency for presentation to the class. –Class: –Attribute: –Behavior: –Object: –Association: –Inheritance: –Aggregation: Assignment: Identifying OO Properties
18
CSCI 265Dale Roberts Sample Package View
19
CSCI 265Dale Roberts Sample Class View Notice that this sample class view does not include visibility indicators. Diamond implies composition: All MediaTopics together comprise a CardCatalog.
20
CSCI 265Dale Roberts Acknowledgements This presentation is an adaptation of material developed by Jim Stafford, John Hopkins University. Used by permission.
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.