1 / 49

Object Orientation

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.

teige
Télécharger la présentation

Object Orientation

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Object Orientation What, How and Why Will van Beek Independent Consultant www.proWill.nl 18 march 2012

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

  3. Abstraction Basics of Object Orientation. - what is Abstraction ?

  4. What is Abstraction ? Plato’s cave Basics of Object Orientation.

  5. What is Abstraction ? Plato’s cave. Abstraction = model / derivative of reality. Basics of Object Orientation. Modeling Grouping relevant properties and behavior in unambiguous classes.

  6. Abstraction = model of reality What is a Class(ification) ? Aristotle Animal sponges vertebrates worms arthropods mammals reptiles lobsters spiders flies Basics of Object Orientation.

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

  8. Example Basics of Object Orientation. Person PreReqsOK UML Classdiagram attentionLevel satisfactionLevel Name Class payAttention Properties break Behavior askQuestion

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

  10. Delegation Is it really your responsibility ? Principles of Object Orientation

  11. Encapsulation Principles of Object Orientation Implementation Interface

  12. Polymorphism Principles of Object Orientation Implementation comes in many shapes Interface

  13. Polymorphism Start() Principles of Object Orientation Machine Program Skating Pinball Vomitting Writing Device Digging Sailing Engine Driving Marathon Plane

  14. Inheritance Is-a Engine (generic) Engine (Ford) Engine (Volvo) Engine (Volkswagen) Principles of Object Orientation

  15. Delegation Encapsulation Polymorphism Inheritance Principles of Object Orientation – Recap

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

  17. Differences with Procedural Programming.

  18. The Reality of Procedural Programming definevariablehProcashandleno-undo. foreachsuperProc: runvalue(superProc.fileName) persistentsethProc. session:add-super-procedure(hProc). end.

  19. The Reality of Procedural Programming

  20. The Reality of Procedural Programming

  21. Rigidity Fragility Immobility The Reality of Procedural Programming Can we do better ?

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

  23. 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)

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

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

  26. Example – the Animal Farm

  27. Demo

  28. The Procedural way Encapsulation Delegation

  29. The Procedural way Fragile Rigid

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

  31. The Object Oriented way • Let’s talk Interface – how to operate the animals • makeSound

  32. The Object Oriented way – the iAnimalinterface class functionmakeSoundreturns logicalprivate().

  33. Access Modifiers defineprivate variablecTestascharacterno-undo. definepublic variablecTestascharacterno-undo. defineprotectedvariablecTestascharacterno-undo. + public # protected super - private sub

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

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

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

  37. Implementations – the animal class

  38. Implementations – the cat class

  39. Implementations – the dog class

  40. Implementations – the cow class

  41. Implementations – the borg class

  42. Encapsulation / Delegation – animalFarm animalFarm.cls - Animal as iAnimal + visitAnAnimal(pcName)

  43. Encapsulation / Delegation – visit animalFarm.cls - Animal as iAnimal + visitAnAnimal(pcName) visit.cls + animalFarm start.p

  44. Implementations – the animalFarm class

  45. Implementations – the visit class

  46. Implementations – the start procedure

  47. Questions?

  48. Thanks you foryour time

  49. Keep in touch www.proWill.nl progressTrainer@live.com info@proWill.nl proWillvanBeek http://nl.linkedin.com/in/proWill +316 2206 8535

More Related