Introduction to Object-Oriented Software Development 5/27/2019
Object-oriented modelling involves classes functioning as types describing their instances which are called objects. - You look around, and you see one particular chair, a table, a person, and you realize that the objects are related - the person is sitting on the chair by the table. - A system developed by using the object-oriented technique can be seen as a system consisting of a number of objects which cooperate to solve a task. 5/27/2019
Object-oriented modelling includes description of: - object properties - links between objects - object behaviour - You look around, and you see one particular chair, a table, a person, and you realize that the objects are related - the person is sitting on the chair by the table. - A system developed by using the object-oriented technique can be seen as a system consisting of a number of objects which cooperate to solve a task. 5/27/2019
Objects Icons representing “real world objects” of different types. myChair: :Bus :Plane :Truck :Ship PN62001:Car Represented in the UML notation. Anonymous object, only type is given Object name and no type Object name (id) and type At this moment you have x number of busses, one of them is represented by the buss picture. 5/27/2019
Classify Objects = Decide Their Classes Some objects share the same type of qualities so we may formulate a general concept – that is to define a class. This is a form of abstraction - some of the differences between the objects are “abstracted away” (ignored). Furniture myChair: yourChair: theBrownSofa: (a person has a name, the same number of chromosomes, ... ) A class describes a set of objects that have the same type of attributes, behaviour and relationships. 5/27/2019
Class and Objects in the UML Notation Person SSN name address drive() Run() ... class attributes operations (behaviour) Class name person1:Person SSN = 123... name= Jane address=Norway person2:Person SSN = 122... name = James address = USA objects You when you declare the class you select which attributes and operations (behavior) are of interest for your system. Objects of the given class will have individual values for the specified attributes. 5/27/2019
Plato versus Aristotle Plato talked about the ideas (classes) “behind the objects”, e.g., you have the idée horse – which in his view existed - and you have concrete horses. The programming language Self have only prototypes (objects). This is more in accordance with Aristotle: The classes have no existents by they own, the objects have an “immanent form” which makes it an object of a certain class. 5/27/2019
Does the ideas (/concepts/classes) “exist by themselves”? Creating an object by copying a prototype is that different from creating an object by instantiating a class? Copy prototype ~ copy operation is creating a copy of a section of memory. Instantiating a class ~ would involve execution of some code and may be also some copying… 5/27/2019
Making a Model You have a problem domain and you want to make a system that solves some problem in this domain. You single out what is essential for your problem, and you also typically simplify reality. You make a model of your system, ”objects from reality” are mapped ”directly onto objects in the model. chair: car: Tom: Seated in owner model mapping reality 5/27/2019
Subclass and Superclass The class of human beings The subclass of ”female objects” People is superclass of Female Jane: James: Person Female Male The classes represented in the UML notation. Person Female Male 5/27/2019
Class Hierarchy ~ Reuse by Inheritance An employee is a special type of person, so if you already have a Person class and needs an Employee class, then inheritance allows you to reuse class Person. Person SSN name address Employee title department An object of type Employee Jane:Employee SSN = 123... name = Jane address = Norway title = accountant department = accounting inheritance or specialization Employee is a specialisation of Person superclass subclass An object of type Employee is also a Person. An will have all attributes that a Person has plus all of its own. 5/27/2019
Multiple Inheritance UML supports multiple inheritance. Some object-oriented theoreticians claim that multiple inheritance should not be used! (e.g., Java). Cassette volume : Integer Book CassetteBook Some times when we describe a new class we see that this new class should have characteristics from two (or more) existing classes. It is then possible to inherit from both classes. 5/27/2019
One Common Ancestor for All Classes Object hashCode In Java all classes have a common ancestor called Object, e.g., in C++ this is not the case. Person Car E.g., common operations: clone(), getClass() Employee 5/27/2019
Linking Objects Objects are typically connected in some way or another. For example: Jane is married to James, Jane owns a car. ownership Person Car married association Class Model :ownership Object Model (model instance of class model) Jane:Person someWreck:Car Draw associations… :married link James:Person 5/27/2019
Part-of Relation Some objects can be seen as compost of other objects. Head 1 1 Arm 1 Person 2 1 2 Leg 5/27/2019
There Are Typically Many Ways to Classify Objects Jim might be classified as a person, a male person, an employee, a student and so on, the context decides. the classes may overlap (or they may be disjoint) xxx: Big box could be Person small once could be Male and Employee… 5/27/2019
Different Models May be Possible! Person Gender Person gender : String Gender Person Female Male Female Male Gender Person ? Androgyni Female Male Undecided Big box could be Person small once could be Male and Employee… Gender Person Female Male Androgyni 5/27/2019
Objects Have Behaviour operations ~ behaviour time sending a message Synchronous and also asynchronous “message passing”… 5/27/2019
An Object-Oriented Program Objects work together and solve problems. Objects have state, the values of the attributes defines the state. The state change when the values of the attributes change. Objects have identity. Some objects are linked together. The objects communicate by sending messages to each other (messages follows the links). Sending a message is the same as asking an object to perform one of its operations. 5/27/2019