Informática II Prof. Dr. Gustavo Patiño MJ
An object is represented as rectangles with underlined names : Lecturer Class Name Only Y.Welikala : Lecturer Class and Object Name Y.Welikala Object Name Only Informatica II. Facultad de Ingeniería. Universidad de Antioquia
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 Lecturer
Name save() change() delete() empID create()
The second and third sections may be suppressed if they need not be visible on the diagram Lecturer Name save() change() delete() empID create() Lecturer Name empID Lecturer save() change() delete() create() Lecturer Informatica II. Facultad de Ingeniería. Universidad de Antioquia
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 Class Attribute CourseOffering number startTime endTime :CourseOffering Number=CS201 endTime=1230 startTime=1030 Object Attribute Value :CourseOffering Number=CS202 endTime=1500 startTime=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
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 TrainCarriage Aggregation Whole Part Informática II. Facultad de Ingeniería. Universidad de Antioquia
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 ExamPaper Aggregation Whole Part
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.
Unspecified Exactly one Zero or more (many, unlimited) One or more Zero or one Specified range Multiple, disjoint ranges 1 0..* * 1..* ,4..6
StudentSchedule Navigation 0..*1 Multiplicity Informática II. Facultad de Ingeniería. Universidad de Antioquia
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 BankAccount balance number name Withdraw() CreateStatement() Current Withdraw() Savings GetInterest() Withdraw() Subclasses Superclass (parent) Ancestor Descendents Generalization Relationship
A class can inherit from several other classes FlyingThingAnimal AirplaneHelicopterBirdWolfHorse 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
CorporateIndividual TruckTrain Sale SalespersonCustomerVehicleProduct seller buyer Item sold Shipping mechanism
CorporateIndividualTruckTrainAirplane Suppose you need a new type of shipping vehicle … Sale SalespersonCustomerVehicleProduct seller buyer Item sold Shipping mechanism