Object Orientation Concepts, Terminology and a Story. © Allan C. Milne School of Engineering,...

Post on 14-Jan-2016

215 views 2 download

Transcript of Object Orientation Concepts, Terminology and a Story. © Allan C. Milne School of Engineering,...

ObjectObjectOrientationOrientation

Concepts, TerminologyConcepts, Terminologyand a Story.and a Story.

© Allan C. Milne© Allan C. MilneSchool of Engineering, Computing & Applied MathematicsSchool of Engineering, Computing & Applied Mathematics

University of AbertayUniversity of Abertayv12.7.17

Why Object-Orientation ?Why Object-Orientation ?

► It is, in some sense, a natural way of It is, in some sense, a natural way of talking about systems.talking about systems.

►The concepts can be applied bothThe concepts can be applied both

to describe the “real world”, and to describe the “real world”, and

to implement computer software to implement computer software representations of that world.representations of that world.

►Do not confuse these two uses of OO; Do not confuse these two uses of OO; they can be applied independently.they can be applied independently.

Some Technical Advantages.Some Technical Advantages.

►OO encapsulates both data and OO encapsulates both data and functionality.functionality.

►OO distinguishes between internal OO distinguishes between internal operation and external application.operation and external application.

►OO forms a base technology for OO forms a base technology for reusable components.reusable components.

An Object Has … An Object Has …

… … a unique identity.a unique identity.

… … an existence that can be described in an existence that can be described in terms of …terms of …

… … what it is what it is ((statestate))

… … what it doeswhat it does ((behaviourbehaviour))

Some Observations.Some Observations.

► Individual objects may have many Individual objects may have many features in common with other objects.features in common with other objects.

►Objects must normally interact in order Objects must normally interact in order to be useful.to be useful.

►Objects appear both in the “real world” Objects appear both in the “real world” and in our programming space.and in our programming space.

Classification.Classification.

►Objects that exhibit similar Objects that exhibit similar characteristics (i.e. the same kinds of characteristics (i.e. the same kinds of state & behaviour) can be considered to state & behaviour) can be considered to all belong to the same all belong to the same class.class.

►This classification is arbitrary and This classification is arbitrary and depends on the system requirements depends on the system requirements and the experiences of the observer.and the experiences of the observer.

►The unique identity of an The unique identity of an objectobject is is defined by its individual existence.defined by its individual existence.

Classes & Objects.Classes & Objects.

► A A classclass describes the describes the kindkind of state and of state and behaviour an behaviour an objectobject of that class will exhibit. of that class will exhibit.

► A class defines the type of objects.A class defines the type of objects.

► Objects exist as individual entities.Objects exist as individual entities.

► An object is considered to be an An object is considered to be an instanceinstance of of a particular class.a particular class.

A A ClockClock Class. Class.

My alarm clock

Big Ben

The office clock

Class Clock

Objects

Abstraction.Abstraction.

► Identifying objects as belonging to the same Identifying objects as belonging to the same class reflects the level of class reflects the level of abstractionabstraction (generality) within the system.(generality) within the system.

► The level of abstraction is determined by the The level of abstraction is determined by the level of detail in the criteria used for level of detail in the criteria used for identifying objects as belonging to a class.identifying objects as belonging to a class.

► Thus objects may be classified at different Thus objects may be classified at different levels of detail.levels of detail.

Inheritance.Inheritance.

► If objects are classified at different levels of If objects are classified at different levels of detail we can put their classes into a detail we can put their classes into a classification hierarchy.classification hierarchy.

► The most abstract class is at the top and the The most abstract class is at the top and the most detailed class at the bottom.most detailed class at the bottom.

► InheritanceInheritance means that a class contains all means that a class contains all the characteristics of the class above it in the the characteristics of the class above it in the hierarchy.hierarchy.

A Class Hierarchy.A Class Hierarchy.

A n a log u e D ig ita l

C lock W atch S u n d ia l

T im ep iece

Message Passing.Message Passing.

► Interaction between objects is accomplished Interaction between objects is accomplished through through message passing.message passing.

► Passing a message to an object is a request Passing a message to an object is a request for it to exhibit some part of its behaviour.for it to exhibit some part of its behaviour.

► There are 2 general types of messagesThere are 2 general types of messages command messagescommand messages (do this...)(do this...) query messagesquery messages (what is...)(what is...)

Methods & Message Methods & Message Passing.Passing.

► MethodsMethods define the type of behaviour that an define the type of behaviour that an object can exhibit.object can exhibit.

► A message can thus be defined in terms ofA message can thus be defined in terms of the identity of the target object for the message,the identity of the target object for the message, the method which exhibits the desired message the method which exhibits the desired message

processing behaviour, andprocessing behaviour, and any additional information (parameters) required any additional information (parameters) required

by the method.by the method.

► The methods of an object define the set of The methods of an object define the set of messages that can be sent to the object.messages that can be sent to the object.

So What Is Object So What Is Object Orientation?Orientation?

► It is a technique for “thinking about” the It is a technique for “thinking about” the architecture and operation of systems.architecture and operation of systems.

► It is a way of modeling a system in It is a way of modeling a system in terms of the objects which make it up.terms of the objects which make it up.

► It allows us to classify together objects It allows us to classify together objects with similar characteristics.with similar characteristics.

Object Orientation … Object Orientation …

… … allows us to abstract the model using allows us to abstract the model using classes & class hierarchies.classes & class hierarchies.

… … identifies the relationships & identifies the relationships & interactions between objects.interactions between objects.

… … provides a model that can be used provides a model that can be used directly in a software implementation.directly in a software implementation.

A Story Through Quotes.A Story Through Quotes.

Following are some quotes that tell a Following are some quotes that tell a story …story …

think about what the quotes mean;think about what the quotes mean;

how they are linked together; andhow they are linked together; and

what the story they are telling is.what the story they are telling is.

"A C program is like a fast dance on a "A C program is like a fast dance on a newly waxed dance floor by people newly waxed dance floor by people carrying razors." carrying razors."

Waldi RavensWaldi Ravens

"I invented the term 'Object-Oriented', and I "I invented the term 'Object-Oriented', and I can tell you I did not have C++ in mind.“ can tell you I did not have C++ in mind.“

Alan Kay (inventor of SmallTalk)Alan Kay (inventor of SmallTalk)

"The great thing about Object Oriented "The great thing about Object Oriented code is that it can make small, simple code is that it can make small, simple problems look like large, complex ones." problems look like large, complex ones."

AnonAnon

““Assumption is the mother of all screw-Assumption is the mother of all screw-ups." ups."

AnonAnon

"Debugging is twice as hard as writing "Debugging is twice as hard as writing the code in the first place. Therefore, if the code in the first place. Therefore, if you write the code as cleverly as you write the code as cleverly as possible, you are, by definition, not possible, you are, by definition, not smart enough to debug it." smart enough to debug it."

Brian W. KernighanBrian W. Kernighan

““Never increase, beyond what is Never increase, beyond what is necessary, the number of entities necessary, the number of entities required to explain anything" required to explain anything"

William of Ockham (1285-1349)William of Ockham (1285-1349)

"the more dogmatic you are about "the more dogmatic you are about applying a design method, the fewer applying a design method, the fewer real-life world problems you will solve" real-life world problems you will solve"

P.J. Plauger (1993)P.J. Plauger (1993)

"Beware of bugs in the above code; I "Beware of bugs in the above code; I have only proved it correct, not tried have only proved it correct, not tried it." it."

Donald E. KnuthDonald E. Knuth

"On two occasions I have been "On two occasions I have been asked [by members of asked [by members of Parliament!]: 'Pray, Mr. Babbage, if Parliament!]: 'Pray, Mr. Babbage, if you put into the machine wrong you put into the machine wrong figures, will the right answers figures, will the right answers come out ?' I am not able rightly to come out ?' I am not able rightly to apprehend the kind of confusion of apprehend the kind of confusion of ideas that could provoke such a ideas that could provoke such a question." question."

Charles BabbageCharles Babbage