Introduction to Object-oriented Software Development

20
08/24/22 Introduction to Object-oriented Software Development, page no. 1, Introduction to Introduction to Object-oriented Object-oriented Software Software Development Development

description

Introduction to Object-oriented Software Development. Object-orientation Is a Modeling Technique. We perceive the world as a world of objects . Y ou look around and you see a chair, a table, a person, and the objects are related in one way or another. - PowerPoint PPT Presentation

Transcript of Introduction to Object-oriented Software Development

Page 1: Introduction to Object-oriented Software Development

04/19/23Introduction to Object-oriented Software Development, page no. 1,

Introduction toIntroduction toObject-oriented Software Object-oriented Software

DevelopmentDevelopment

Page 2: Introduction to Object-oriented Software Development

04/19/23Introduction to Object-oriented Software Development, page no. 2,

Object-orientation Is a Object-orientation Is a Modeling TechniqueModeling Technique

• We perceive the world as We perceive the world as a world of a world of objectsobjects.. You look around and you see a chair, a table, a person, and the objects are related in one way or another.

• The object-oriented technique tries to imitate the way we thinkimitate the way we think, 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.

Page 3: Introduction to Object-oriented Software Development

04/19/23Introduction to Object-oriented Software Development, page no. 3,

ObjectsObjects• You find objects of different types in the

real world.• At this moment you have x number of

busses, one of them is represented by the buss picture.

myChair: :Bus :Plane

:Truck :Ship PN62001 :Car

• The picture of the bus is a symbol and not the real thing.

• In UML you can use icons to represent objects or: use rectangles and specify object name and object type.

Anonymous object, only type is given

Object name and no typeObject name and type

Page 4: Introduction to Object-oriented Software Development

04/19/23Introduction to Object-oriented Software Development, page no. 4,

When You Classify Objects When You Classify Objects You You DecideDecide Their Type Their Type

myChair: yourChair: theBrownSofa:

Jane: James:

Furniture

People

Female Male

The class of ”people objects”

The subclass of ”female objects”

Page 5: Introduction to Object-oriented Software Development

04/19/23Introduction to Object-oriented Software Development, page no. 5,

There Are Typically Many There Are Typically Many Ways to Classify ObjectsWays to Classify Objects

The classes overlap

xxx:

xxx:

xxx:

xxx:

xxx:

xxx:

xxx:

xxx:

xxx:

xxx:

xxx:

xxx:

xxx:

xxx:

xxx:

xxx:

xxx:

xxx:

xxx:

• Jim might be classified as a person, a male person, an employee, a student and so on, the context decides.

Page 6: Introduction to Object-oriented Software Development

04/19/23Introduction to Object-oriented Software Development, page no. 6,

1-1- ObjectsObjects and Class and Class• By watching the objects we recognize that some objects share the some objects share the

same type of qualitiessame type of qualities (a person has a name, the same number of chromosomes, ... ) so we might formulate a general concept – so we might formulate a general concept – that that is is define a classdefine a class. This process is called abstraction.

• Plato talked about the ideas behind, you have the idée horse and you have concrete horses. For him, the ideas had their own existence, this idée concept is very close to the class concept.

• When you program in an object-oriented language you can define your own classes and make objects of the different classes.(So is object-oriented programming a divine activity or what?)

Page 7: Introduction to Object-oriented Software Development

04/19/23Introduction to Object-oriented Software Development, page no. 7,

2-2- ObjectsObjects and Class and Class• There are object-oriented languages were you do not have classes,

only objects (e.g. Self). This is more like the way Aristoteles figured the world: the classes have no exsistens by they own, the objects have an immanent form which makes it an object of a certain class.

• The more common languages like C++ and Java lets you define classes and than make objects of this classes.

• A class describes a set of objects that share the same attributes, A class describes a set of objects that share the same attributes, behaviour and relationshipsbehaviour and relationships.

Page 8: Introduction to Object-oriented Software Development

04/19/23Introduction to Object-oriented Software Development, page no. 8,

ObjectsObjects in UML in UML

”A concrete manifestation of an abstraction; An entity with a welldefined boundary and identity that encapsulates state and behavior; An instance of a class.”

Page 9: Introduction to Object-oriented Software Development

04/19/23Introduction to Object-oriented Software Development, page no. 9,

Making a ModelMaking 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 into objects in the model.

reality

chair:

car:

Tom:

Seated in

owner

modelmappingrelation (link)

Page 10: Introduction to Object-oriented Software Development

04/19/23Introduction to Object-oriented Software Development, page no. 10,

Class and Objects in UMLClass and Objects in UML

Jane:Person

SSN = 123...name= Janeaddress=Norway

James:Person

SSN = 122...name = Jamesaddress = USA

objects

Person

SSNnameaddress

drive()Run()...

class

attributes

operations

Class name

• You when you declare the class you select which attributes and operations are of interest for your system.

• Objects of the given class will have individual values for the specified attributes.

Page 11: Introduction to Object-oriented Software Development

04/19/23Introduction to Object-oriented Software Development, page no. 11,

Class Hieararchy ~ Class Hieararchy ~ InheritanceInheritance

• An employee is a special type of person, so if you already have a Person class and need a Employee class then it should be possible to take advantage of the already existing Person class.

Person

SSNnameaddress

Employee

titledepartment

An object of type Employee is also a Person.An will have all attributes that a Person has plus all of its own.

Jane:Employee

SSN = 123...name = Janeaddress = Norwaytitle = accountantdeparment = accounting

inheritance or specialization

Employee is aspesializationof Person

superclass

subclass

Page 12: Introduction to Object-oriented Software Development

04/19/23Introduction to Object-oriented Software Development, page no. 12,

MultipleMultipleInheritanceInheritance

Person

name

Employee

titleOwner

WorkingOwner

• 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.

• Not all object-oriented language support multiple inheritance (e.g. Java), some object-oriented theoreticians claim that multiple inheritance should not be used!

Cassette

volume : Integer

Book

volume : Integer

CassetteBook

Page 13: Introduction to Object-oriented Software Development

04/19/23Introduction to Object-oriented Software Development, page no. 13,

One Common Ancestor for One Common Ancestor for All ClassesAll Classes

Object

getClass()hashCode()equals()clone()toString()notify()notifyAll()wait()wait()wait()finalize()Object()

Person Car

Employee

• In Java all classes have a common ancester called Object, this is not the case in C++.

Page 14: Introduction to Object-oriented Software Development

04/19/23Introduction to Object-oriented Software Development, page no. 14,

1 - 1 - RelationshipsRelationships• Objects are typically connected in some way or another. For

example: Jane is married to James, Jane owns a car.

Jane:Person

SSN = 123...name= Janeaddress=Norway

James:Person

SSN = 122...name = Jamesaddress = USA

someWreck:Car

married

owns

Page 15: Introduction to Object-oriented Software Development

04/19/23Introduction to Object-oriented Software Development, page no. 15,

2 - 2 - RelationshipsRelationships• Some objects can be seen as consisting of other

objects.

Person

Leg

Head

Arm 2

1

2

1

1

1

Page 16: Introduction to Object-oriented Software Development

04/19/23Introduction to Object-oriented Software Development, page no. 16,

Objects Have BehaviourObjects Have Behaviour

Person

CoffeeMachine

pourCoffe()addMilk()addOneLumpOfSugger()

operations ~ behaviour

Jane : Person office : CoffeeMachine

pourCoffe( )

addOneLumpOfSugger( )

addOneLumpOfSugger( )

addMilk( )

time

sending a message

Page 17: Introduction to Object-oriented Software Development

04/19/23Introduction to Object-oriented Software Development, page no. 17,

An Object-orientedAn Object-orientedProgramProgram

• Objects work togetherObjects work together and solves problems.

• Objects have stateObjects have state, the values of the attributes defines the state. The state change when the attribute values changes.

• Some objects are linked togetherSome objects are linked together.

• The objects communicate by sending messagesobjects 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 it’s operations.

Page 18: Introduction to Object-oriented Software Development

04/19/23Introduction to Object-oriented Software Development, page no. 18,

1 - 1 - Paradigms of Paradigms of programming programming

• Imperative programmingImperative programming (FORTRAN, C): • Algorithm abstraction (give name to a sequence of

instructions)• Focus on the algorithms• Data in separate structures• Stepwise refinement (structured programming)

• Datamodelling Datamodelling (COBOL, SQL):• Focus on data an the static relationships• Data abstractions, give name to a group of data (records)

Page 19: Introduction to Object-oriented Software Development

04/19/23Introduction to Object-oriented Software Development, page no. 19,

2 - 2 - Paradigms of Paradigms of programming programming

• Object-oriented programmingObject-oriented programming (Smalltalk, C++, Java):• Data and behaviour is put together

• More mathematical approachesMore mathematical approaches:• Logical programming (Prolog)• Functional programming (Lisp)

Page 20: Introduction to Object-oriented Software Development

04/19/23Introduction to Object-oriented Software Development, page no. 20,

The First Object-orientedThe First Object-oriented

Language: SimulaLanguage: Simula

• Introduced in 1966 (or earlier).• Created by Ole-Johan Dahl and Kristen Nygaard.• A language for simulation but became a general purpose

programming language.

Allan Key: “Simula is a major improvement of most of its sucessors”