Tải bản đầy đủ (.ppt) (35 trang)

1-OO-Basics.ppt

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (578.15 KB, 35 trang )

07/16/14
1
OO - Basics
2
07/16/14
Introduction to Object Orientation Topics

Basic Principles of Object Orientation

Basic Concepts of Object Orientation

Strengths of Object Orientation
3
07/16/14
Object Orientation
Encapsulation
Abstraction
Hierarchy
Polymorphism
Basic Principles of Object Orientation
4
07/16/14
What Is Abstraction?

The essential characteristics of an entity that
distinguishes it from all other kinds of entities.

Defines a boundary relative to the perspective of
the viewer.

Is not a concrete manifestation, denotes the ideal


essence of something.
5
07/16/14
Salesperson
Not saying
Which
salesperson
– just a
salesperson
in general!!!
Customer
Product
Manages Complexity
What is Abstraction?
6
07/16/14
What Is Encapsulation?
Improves Resiliency

Hides implementation from clients.

Clients depend on interface.
7
07/16/14
Encapsulation

"Encapsulation is a mechanism used to hide the data,
internal structure, and implementation details of an object.
All interaction with the object is through a public interface
of operations." (Craig Larman)


A boundary exists around each object; the boundary
encapsulates the object’s characteristics (data elements)
and behaviors (functionality).

The reason for hiding features is to:
(1) keep users from touching parts of the object they shouldn’t touch;
(2) allows creator of the object to change the object’s internal working
without affecting the users of the object.
8
07/16/14
What Is Polymorphism?
Manufacturer A
Manufacturer B
Manufacturer C
OO Principle:
Encapsulation
Remote Control

The ability to hide many different
implementations behind a single interface.
9
07/16/14
Polymorphism

Occurs with inheritance.

Different subclasses may have different
implementations of the identical operations


Allows you to treat an object as the base class,
rather than as a specific inherited type.

Programmer doesn’t have to keep track of the
specific subclasses, the system selects the correct
operation based on the object type.

Accomplished at run time using dynamic binding.

lets you substitute objects that have identical interfaces for
each other at run-time.
10
07/16/14
Decreasing
abstraction
Increasing
abstraction
Asset
RealEstate
Savings
BankAccount
Checking
Stock
Security
Bond
Elements at the same level of the hierarchy
should be at the same level of abstraction
What is Hierarchy?

Levels of abstraction

11
07/16/14
Basic Concepts of Object Orientation

Object

Class

Attribute

Operation

Interface

Package

Relationships
12
07/16/14

Informally, an object represents an entity, either
physical, conceptual, or software

Physical entity

Conceptual entity

Software entity
Truck
Chemical Process

Linked List
What is an Object?
13
07/16/14
A More Formal Definition

An object is a concept, abstraction, or thing with
sharp boundaries and meaning for an application

An object is something that has:

State

Behavior

Identity
14
07/16/14
OO Principle: Abstraction
What is a Class?

A class is a description of a group of objects with
common properties (attributes), behavior
(operations), relationships, and semantics

An object is an instance of a class

A class is an abstraction in that it:

Emphasizes relevant characteristics


Suppresses other characteristics
15
07/16/14
a + b = 10
Class
Course
Properties
Name
Location
Days offered
Credit hours
Start time
End time
Behavior
Add a student
Delete a student
Get course roster
Determine if it is full
Sample Class
16
07/16/14
Representing Classes in the UML

A class is represented using a rectangle with three
compartments:

The class name

The structure (attributes)


The behavior (operations)
Professor
- name
- employeeID : UniqueId
- hireDate
- status
- discipline
- maxLoad
+ submitFinalGrade()
+ acceptCourseOffering()
+ setMaxLoad()
+ takeSabbatical()
+ teachClass()
17
07/16/14
Classes of Objects

How many classes do you see?
18
07/16/14
Objects
Class
Professor Smith
Professor Jones
Professor Mellon
Professor
Classes and Objects Relationship

A class is an abstract definition of an object


It defines the structure and behavior of each object in the
class

It serves as a template for creating objects

Objects are grouped into classes
19
07/16/14
What Is an Attribute?

An attribute is a named property of a class that
describes the range of values that instances of the
property may hold.

A class may have any number of attributes or no attributes
at all.
Attributes
Student
- name
- address
- studentID
- dateOfBirth
20
07/16/14
What Is an Operation?

A service that can be requested from an object to
effect behavior. An operation has a signature,
which may restrict the actual parameters that are

possible.

A class may have any number of operations or
none at all.
Operations
Student
+ get tuition()
+ add schedule()
+ get schedule()
+ delete schedule()
+ has prerequisites()
21
07/16/14
Tube
Pyramid
Cube
Shape
Draw
Move
Scale
Rotate
<<interface>>
Realization relationship
(s tay tuned for realiz ation re lationships)
What is an Interface?

Interfaces formalize polymorphism

Interfaces support “plug-and-play” architectures
22

07/16/14
Interface
How do you get an object to do useful work for you?

Objects are known only through their interfaces

Every object presents an interface to the world.

Interface determines what you can get an object to
do.

Represent a "contract" with other objects.

Communicate with objects by sending messages to
them; an object’s interface is the set of messages
an object will respond to.
23
07/16/14

A package is a general purpose mechanism for
organizing elements into groups

A model element which can contain other model
elements

Uses

Organize the model under development

A unit of configuration management

Package Name
OO Principle:
Modularity
What is a Package?
24
07/16/14
Relationships

Association

Aggregation

Dependency

Generalization

Realization
ConsoleWindow
Window
open()
close()
move()
display()
handleEvent()
Event
DialogBox Control
association
generalization
25
07/16/14

Professor
University
Works for
Class
Association
Association Name
Relationships: Association

Models a semantic connection among classes

Tài liệu bạn tìm kiếm đã sẵn sàng tải về

Tải bản đầy đủ ngay
×