490 likes | 777 Views
Object Orientation. What, How and Why. Will van Beek. Independent Consultant www.proWill.nl 18 march 2012. What is Object Orientation ? Basics & Principles Why use Object Orientation ? How to use Object Orientation Demo – the Animal Farm. Object Orientation – What, How and Why.
E N D
Object Orientation What, How and Why Will van Beek Independent Consultant www.proWill.nl 18 march 2012
What is Object Orientation ? Basics & Principles Why use Object Orientation ? How to use Object Orientation Demo – the Animal Farm Object Orientation – What, How and Why
Abstraction Basics of Object Orientation. - what is Abstraction ?
What is Abstraction ? Plato’s cave Basics of Object Orientation.
What is Abstraction ? Plato’s cave. Abstraction = model / derivative of reality. Basics of Object Orientation. Modeling Grouping relevant properties and behavior in unambiguous classes.
Abstraction = model of reality What is a Class(ification) ? Aristotle Animal sponges vertebrates worms arthropods mammals reptiles lobsters spiders flies Basics of Object Orientation.
Abstraction = model of reality Class = abstract definition of properties, behavior and relations to other classes What is an Object ? Concrete instance of a class. Basics of Object Orientation. Example
Example Basics of Object Orientation. Person PreReqsOK UML Classdiagram attentionLevel satisfactionLevel Name Class payAttention Properties break Behavior askQuestion
What is Object Orientation ? Basics & Principles Why use Object Orientation ? How to use Object Orientation Demo– the Animal Farm Object Orientation – What, How and Why
Delegation Is it really your responsibility ? Principles of Object Orientation
Encapsulation Principles of Object Orientation Implementation Interface
Polymorphism Principles of Object Orientation Implementation comes in many shapes Interface
Polymorphism Start() Principles of Object Orientation Machine Program Skating Pinball Vomitting Writing Device Digging Sailing Engine Driving Marathon Plane
Inheritance Is-a Engine (generic) Engine (Ford) Engine (Volvo) Engine (Volkswagen) Principles of Object Orientation
Delegation Encapsulation Polymorphism Inheritance Principles of Object Orientation – Recap
What is Object Orientation Why use Object Orientation ? Differences with Procedural Programming How to use Object Orientation Demo– the Animal Farm Object Orientation – What, How and Why
The Reality of Procedural Programming definevariablehProcashandleno-undo. foreachsuperProc: runvalue(superProc.fileName) persistentsethProc. session:add-super-procedure(hProc). end.
Rigidity Fragility Immobility The Reality of Procedural Programming Can we do better ?
What is Object Orientation ? Why use Object Orientation ? How to use Object Orientation Principles of sound design Demo– the Animal Farm Object Orientation – What, How and Why
Low & Loose Coupling (Law Of Demeter) Principles of Good / Sound Design. Swiss Knife Classes High coupling Lots of classes with different functionality inextricably connected Don’t talk to strangers ! The principle of least knowledge An object knows only about himself and its direct parent (Superclass)
High Cohesion Principles of Good / Sound Design. Do only 1 thing ! The principle of single responsibility All other responsibilities have been moved to other classes Low Cohesion Different functionalities in 1 class
What is Object Orientation ? Why use Object Orientation ? How to use Object Orientation Demo– the Animal Farm the Procedural way the Object Oriented way Object Orientation – What, How and Why
The Procedural way Encapsulation Delegation
The Procedural way Fragile Rigid
The Object Oriented way • Let’s talk Interface – how to operate the coffee machine • Where to put the cup, the coffee & the water • How to turn it On/Off
The Object Oriented way • Let’s talk Interface – how to operate the animals • makeSound
The Object Oriented way – the iAnimalinterface class functionmakeSoundreturns logicalprivate().
Access Modifiers defineprivate variablecTestascharacterno-undo. definepublic variablecTestascharacterno-undo. defineprotectedvariablecTestascharacterno-undo. + public # protected super - private sub
Polymorphism – one interface, multiple implementations System.Media. Soundplayer • + SoundLocation • + Play iAnimal.cls + makeSound cat.cls + makeSound dog.cls • + makeSound cow.cls • + makeSound borg.cls • + makeSound • Initiate the animal’s vocal cords • Specify the name of the sound file • Play the sound file
Inheritance – a cat/dog/cow/borgis-an animal System.Media. Soundplayer • + SoundLocation • + Play iAnimal.cls + makeSound cat.cls + makeSound dog.cls • + makeSound cow.cls • + makeSound borg.cls • + makeSound animal.cls -vocalCords #soundFile -initializeVocalCords + makeSound
Encapsulation / Delegation – vocalCords System.Media. Soundplayer • + SoundLocation • + Play iAnimal.cls + makeSound cat.cls + makeSound dog.cls • + makeSound cow.cls • + makeSound borg.cls • + makeSound animal.cls -vocalCords #soundFile -initializeVocalCords + makeSound
Encapsulation / Delegation – animalFarm animalFarm.cls - Animal as iAnimal + visitAnAnimal(pcName)
Encapsulation / Delegation – visit animalFarm.cls - Animal as iAnimal + visitAnAnimal(pcName) visit.cls + animalFarm start.p
Keep in touch www.proWill.nl progressTrainer@live.com info@proWill.nl proWillvanBeek http://nl.linkedin.com/in/proWill +316 2206 8535