Object Principles - PowerPoint PPT Presentation

1 / 48
About This Presentation
Title:

Object Principles

Description:

... class and make the necessary modifications to the new pasted class. ... an abstract class, while 'truck' and 'car' are concrete classes. ... Tips. Eliminated ... – PowerPoint PPT presentation

Number of Views:33
Avg rating:3.0/5.0
Slides: 49
Provided by: drewh6
Category:

less

Transcript and Presenter's Notes

Title: Object Principles


1
Object Principles
  • Abstraction
  • Encapsulation
  • Information Hiding
  • Inheritance
  • Persistence
  • Aggregation
  • Collaboration
  • Polymorphism

2
Abstraction
  • Is the generalization process of the problem
    domain.
  • Concentrates on important essentials while
    disregarding nonessential details.
  • Reduces complexity.

3
AbstractionA Fundamental Element in Software
Engineering
Problem Domain
Program Model
Abstraction
Implementation
Transformation
Conceptual Model
Software Model
4
AbstractionAn OO Example
Memory chips Capacitors IC boards Resistors Induc
tors
Computer
Too much detail
Appropriate level of detail
Too little detail
Keyboard Monitor Mouse Base unit
Motherboard/RAM Hard disk/Floppy
disk Keyboard/Mouse Monitor/Display card IO
ports/Control card
5
Encapsulation
  • Is a mechanism that allows us to hide the
    implementation of the object knows or does.
  • Functionality are encapsulated into a class
    method. The method can only be initiated by the
    object itself or by messages sent from other
    objects.
  • Implication The behavior of a class can be
    modified without affecting other components
    within the system.

6
Information Hiding
  • The restriction of access to attributes (data).
  • The underlying idea is encapsulation.
  • A technique that has been well known in the
    structured design. (OO enforces it.)
  • Implication
  • - If one class wants information about another
    class, it should ask for it instead of just
    taking it.
  • - The attributes of a class can be modified
    without affecting other components within the
    system.

7
Information HidingLevel of Abstraction
Users
Logical View
Physical View
Database
8
Encapsulation and Information HidingExample I
Panel
Gear shift
Pedals
Wheel
9
Encapsulation and Information HidingExample II
10
Encapsulation vs. AbstractionThe Focus
Abstraction
Encapsulation
Observable behavior of an object
Implementation of the behavior
Hides implementation details
Discovers the essence of behavior
Analysis
Design
11
Inheritance
  • Reason Very often, two or more classes share the
    same attributes and/or methods.
  • Idea Do not write the same code for similar
    classes over and over again. Just make a copy of
    the original class and make the necessary
    modifications to the new pasted class.

12
InheritanceSubclass and Superclass
  • If class B inherits from class A, then B is
    a subclass of A and A is a superclass of B.
  • Everything that a superclass knows or does, the
    subclass knows or does.
  • The notations

Class A
Class B
13
InheritanceSingle and Multiple
  • Single inheritance when a class inherits from
    only one other class.
  • Multiple inheritance when a class inherits from
    more than one class.

Superclass
Supperclass A
Superclass B
Class Hierarchy
Subclass A
Subclass B
Subclass
Multiple
Single
14
InheritanceExample I - Single
Student
Professor
Student ID Name Major Address Phone
Professor ID Name Department Address Phone
Before
Enroll in a course Drop a course Pay
tuition Request transcript Buy a parking
permit Check out a book
Teach a course Request a transcript Submit grade
report Buy a parking permit Check out a book
15
InheritanceExample I - Single
Person
Address Phone Name
Student
Professor
Buy a parking permit Check out a book
Student ID Major
Professor ID Department
Enroll in a course Drop a course Pay
tuition Request transcript
Teach a course Request a transcript Submit grade
report
After
16
InheritanceExample II - Multiple
Student
Employee
Student ID Name Major Address Phone
Employee ID Name Work Unit Address Phone
Before
Student Employee
Enroll in a course Drop a course Pay
tuition Request transcript Buy a parking
permit Check out a book
Enroll a course Buy a parking permit Check out a
book Record time card Request a paycheck
?
17
InheritanceExample II - Multiple
Student Employee
Student ID Employee ID Name Work
Unit Major Address Phone
Enroll in a course Record time card Drop a
course Request a paycheck Pay tuition Request
transcript Buy a parking permit Check out a book
After
18
Inheritance vs. Relational DB
  • Single inheritance vs. Normalization
  • Multiple inheritance vs. Join

19
Class HierarchyA set of classes that are related
through inheritance.
Person
Student
Employee
Professor
Student Employee
20
Class HierarchyExample - Vehicle
  • Vehicle Mini Truck
  • Truck Regular Truck
  • Goods Train Car
  • Non-Motorized Passenger
  • Passenger Goods Carrying
  • Motorized Passenger Bus
  • Motor Cycle Motor Cycle
  • Bicycle Mini Bus
  • Small Car Large Car
  • Van Medium Car
  • Mazda 626 Ford Taurus

21
Abstract and Concrete Classes
  • Vehicle is an abstract class, while truck and
    car are concrete classes.
  • The main difference is that objects are
    instantiated from concrete classes but not from
    abstract classes.
  • More examples Person, Music, ...

22
Persistence and Transient Objects
  • A persistent object is an object that needs to be
    saved to permanent storage for future use, while
    a transient object is created at run time for
    temporary use.
  • Examples A customer is a persistent object,
    while a customer editing screen is a transient
    object.
  • Business entities are usually persistent.
  • Interface classes are usually transitory.

23
Persistent ObjectsExample - Bill of Materials
A
2B
3D
C
2F
4E
2H
5G
3J
I
24
Object-Oriented Databases
  • Can store both variable and fixed-length data.
  • Can maintain complex instance relationships and
    traverse these relationships quickly.

25
Relational DatabasesExample - Bill of Materials
26
Object-Oriented DatabasesExample - Bill of
Materials
27
Instance Relationships
  • Objects are associated with one another through
    instance relationships.
  • These relationships need to be identified and
    documented as part of the conceptual model.
  • Instance relationships can be inherited.

28
Instance RelationshipsCardinality and Optionality
  • Cardinality is a word for how many, and
    optionality is a word for whether or not you have
    to do it.
  • Instance relationships (or sometimes called
    object associations) are maintained through the
    combination of attributes and methods. The
    attributes store the information necessary to
    maintain the relationship, and methods keep the
    attributes up-to-date.

29
Instance RelationshipsCardinality and
Optionality Notations
Instance Relationship
1
2
3
4
Class A
Class B
Cardinality (1 4)
Optionality (2 3)
many
must
one
may
30
Instance RelationshipsCardinality and
Optionality Example I
section of
takes
Student
Seminar
Course
How do you read this diagram?
31
Instance RelationshipsCardinality and
Optionality Example I
  • A student takes one or more seminars.
  • A seminar is taken by zero or more students.
  • A seminar is a section of a course.
  • A course has one or more sections.

32
Instance RelationshipsCardinality and
Optionality Example II
manages
holds
Employee
Position
Recursive Instance Relationship
How do you read this diagram?
33
Instance RelationshipsCardinality and
Optionality Example II Diagram the relationships
  • An employee holds one and only one position.
  • A position may be held by one employee (some
    positions go unfilled),
  • An employee is managed by one and only one
    employee.
  • An employee manages one or more employees.

34
Instance RelationshipsCardinality and
Optionality Example III
Diagram the relationship between a customer and
an order.
35
Instance RelationshipsCardinality and
OptionalityTips
  • Eliminated associations. If one or more objects
    in an association have been eliminated, the
    association must also be eliminated.
  • Irrelevant associations. Discard any
    associations outside the problem domain.
  • Ternary associations. Associations among three
    or more object types can be decomposed into
    binary associations.

36
Aggregation
  • Some objects are made up of other objects
    (part) and so is considered as aggregate
    objects.
  • Aggregation represents the is-part-of
    relationships.
  • One class can be aggregated from one or more
    parts.
  • Aggregation relationships can be inherited.

37
AggregationExample I
Aggregated Class
Aggregation Relationship
Part Class
Shipment
Delivery Item
Airplane
Engine
38
AggregationExample II
Row
Spreadsheet
Multiple Aggregation
Column
Recursive Aggregation
Team
Employee
Describe the association and aggregation
relationships.
39
AggregationExample II
  • Diagram the association and aggregation
    relationships between the Order_Head and the
    Order_Line.

40
Collaboration
  • Collaboration occurs when an object asks another
    object for information or asks it to do something
    by sending each other messages.
  • In this case, no particular object has all the
    intelligence, each one takes care of its own
    responsibilities, and leaves the others to deal
    with theirs.

41
CollaborationTips
  • There must be some sort of relationships between
    collaborated objects.
  • There must be a corresponding method in the
    receiving object.
  • There might be a return value.
  • There may or may not be parameters.
  • Messages are not data flows.

42
CollaborationExample I
Student
Seminar
Request for of open seats
Student ID Name Major Address Phone
Room ID Section Max Seat of Seats Taken Time
Request for adding a course
Request for a seminar list
Enroll in a course Drop a course Pay
tuition Request transcript Buy a parking
permit Check out a book
Add a student Drop a student Calculate seats
left Give student list Give a seminar list
takes
With Parameters? Return a value?
43
CollaborationExample II
Diagram the collaboration relationships between a
bank customer class and an account class.
44
Persistent vs. TransitoryInstance Relationships
  • Persistent instance relationships are those that
    are permanent and need to be saved to disk.
  • Transitory instance relationships are temporary
    in nature and need not to be saved to disk.
  • Transitory relationships usually involve at least
    one transitory object.

45
Persistent vs. TransitoryInstance
RelationshipsExample
Edit
Student
Student-Edit -Screen
46
Persistent vs. TransitoryInstance
RelationshipsExample - Print a Student
Transcript (a)
Student Transcript Cal Poly Pomona
Student ID _________ Student Name
____________ Student Address ____________________
___________
Course ID Course Name Course Description
Grade
47
Persistent and Transitory Instance Relationships
Example (b)
Transitory
Student
Transcript
Request for student name
Student ID Name Address List of seminars
Format ID
Get student name Get student address Get seminars
enrolled Get seminar info Output
Request for student address
Give name Give address Give seminars
Request for list of seminars
Request for seminar info
Persistent
Persistent
Seminar
Course
Seminar ID Course ID List of students Grade
Transitory
Course ID Name Desc
Request for course name
Request for course desc
Get course name Get course desc Give seminars info
Give course name Give course desc
48
Polymorphism
  • Polymorphism is the principle that instances of
    various classes can be treated by the other
    objects the same way within the system.
  • For example, a person in an university can be a
    student, a employee, or a professor. When that
    person object is instantiated in different forms,
    it can be treated the same by the other objects.
  • The idea is to reduce duplicated codes.
Write a Comment
User Comments (0)
About PowerShow.com