informática ii prof. dr. gustavo patiño mj 16- 18 12-09-2013

25
Informática II Prof. Dr. Gustavo Patiño MJ 16- 18 12-09-2013

Upload: kory-bradford

Post on 18-Dec-2015

217 views

Category:

Documents


1 download

TRANSCRIPT

Informática IIProf. Dr. Gustavo PatiñoMJ 16- 1812-09-2013

An object is represented as rectangles with underlined names

: LecturerClass Name Only

Y.Welikala : LecturerClass and Object Name

Y.Welikala

Object Name Only

Informatica II. Facultad de Ingeniería. Universidad de Antioquia. 2013-2

Informatica II. Facultad de Ingeniería. Universidad de Antioquia. 2013-2

Intro to OO 201

Algebra 110

Electricity 100

Algorithms 202

ThermalDynamics 110

Electronics 110

English 101

A class is represented using a compartmented rectangle.

Informatica II. Facultad de Ingeniería. Universidad de Antioquia. 2013-2

Lecturer

LecturerName

save()change()

delete()

empID

create()

The second and third sections may be suppressed if they need not be visible on the diagram

LecturerName

save()change()

delete()

empID

create()

LecturerName empID

Lecturer

save()change()

delete()

create()

Lecturer

Lecturer

Informatica II. Facultad de Ingeniería. Universidad de Antioquia. 2013-2

Informatica II. Facultad de Ingeniería. Universidad de Antioquia. 2013-2

CourseOffering

Intro to OO 201

Algebra 110

Algorithms 202

Electricity 101

Electronics 200

English 110

Thermo 110

Informatica II. Facultad de Ingeniería. Universidad de Antioquia. 2013-2

Class

Attribute

CourseOffering

numberstartTimeendTime

:CourseOfferingNumber=CS201

endTime=1230startTime=1030

Object

Attribute Value

:CourseOfferingNumber=CS202

endTime=1500startTime=1300

Attributes are in fact objects.However, fine detail such as date,

integer, etc., should not be modeled.Sometimes it is difficult to decide

whether an attribute should be an object, and vice versa, e.g. qualification as an attribute of person could be modeled as an object.

The same operation (e.g. +) may apply to lots of different classes (polymorphism).

The implementation of an operation is called a method.

Methods are exactly equivalent to procedures and functions in traditional languages. Methods may have arguments. Methods may return a result.

CourseOffering

addStudent

deleteStudent

getStartTime

getEndTime

Class

Operation

Informatica II. Facultad de Ingeniería. Universidad de Antioquia. 2013-2

Classes are types! Types are classes! Programming languages have built-in

classes, such as Real, Integer, Array. In an object language you can

expand and extend the types available, e.g. add complex numbers to the number hierarchy.

Association Aggregation Composition

Generalization

A special form of association that models a whole-part relationship between an aggregate (the whole) and its parts

Train Carriage

Aggregation

WholePart

Informática II. Facultad de Ingeniería. Universidad de Antioquia. 2013-2

A form of aggregation with strong ownership and coincident lifetimes The parts cannot survive the

whole/aggregate

Informática II. Facultad de Ingeniería. Universidad de Antioquia. 2013-2

Exam Paper

Aggregation

WholePart

Multiplicity defines how many objects participate in a relationships The number of instances of one class related

to ONE instance of the other class Specified for each end of the association

Associations and aggregations are bi-directional by default, but it is often desirable to restrict navigation to one direction If navigation is restricted, an arrowhead is

added to indicate the direction of the navigation.

UnspecifiedExactly oneZero or more (many, unlimited)

One or moreZero or oneSpecified rangeMultiple, disjoint ranges

1

0..*

*

1..*

0..1

2..4

2,4..6

Student Schedule

Navigation

0..*1

Multiplicity

Informática II. Facultad de Ingeniería. Universidad de Antioquia. 2013-2

A relationship among classes where one class shares the structure and/or behavior of one or more classes

Defines a hierarchy of abstractions in which a subclass inherits from one or more super classes Single inheritance Multiple inheritance

Generalization is an “is-a-kind of” relationship.

One class inherits from another

BankAccountbalance

numbername

Withdraw()CreateStatement()

Current

Withdraw()

Savings

GetInterest()Withdraw()

Subclasses

Superclass

(parent)

Ancestor

Descendents

Generalization Relationship

A class can inherit from several other classes

FlyingThing Animal

Airplane Helicopter Bird Wolf Horse

multiple inheritance

A subclass inherits its parent’s attributes, operations, and relationships

A subclass may: Add additional attributes, operations,

relationships Redefine inherited operations (use caution)

Common attributes, operations, and/or relationships are shown at the highest applicable level in the hierarchy.

Order

Product

Ship via

Corporate Individual Truck Train

Sale

Salesperson Customer VehicleProduct

seller buyerItem sold

Shipping mechanism

Corporate Individual Truck Train Airplane

Suppose you need a new type of

shipping vehicle …

Suppose you need a new type of

shipping vehicle …

Sale

Salesperson Customer VehicleProduct

seller buyerItem sold

Shipping mechanism