110 likes | 201 Views
Why you should care about Object Orientation (OO). Objects Vs. Dino-Fortran. Iñaki Serraller Vizcaino. Overview. Objectives OO Vs. Procedural Concepts Objects Classes Inheritance Polymorphism Features When to Use OO?. Objectives.
E N D
Why you should care about Object Orientation (OO) Objects Vs. Dino-Fortran IñakiSerraller Vizcaino
Overview • Objectives • OO Vs. Procedural • Concepts • Objects • Classes • Inheritance • Polymorphism • Features • When to Use OO?
Objectives To explain a different programming paradigm and its possible applications Which programming language do you use? ¡To turn you all into Java programmers! Bua Ha HaHa
Objects A dog • Tend to correspond to objects in the real world • Two characteristics: State & Behaviour • Dog state: number of legs (permanent), age (changing) • Dog behaviour: bark, fetch, wag tail, etc. • Composition: objects can be made of other objects • Observe and note
Classes A dog blueprint • Object blueprints Class Dog { String name; int age; Colour colour; bark(); sit(); fetch(Object thing); } • Dog class has colour, dog object is black and white // Create a dog instance Dog lassie = new Dog(“Lassie”, 0, new Colour(“Black”, “White”)); lassie.bark();
Inheritance • Different kinds share traits • All mammals have age and colour • Dog and Cat classes extend the Mammal (super) class • Specialisation • getAgeInHumanYears() would use different multipliers. • Extension • Dog would add bark(), while cat would add meow() • Abstraction – no mammals exist • Hierarchies – different dog breeds A lemur, unhappy to be subclassed
Polymorphism • Can be seen as a consequence of inheritance which allows treating Dogs and Cats as mammals. • The same code can process the age of all mammals • Dog’s bark() and cat’s meow() but all animals speak() • Interfaces • Swimmer adds swim() • Parametric polymorphism allows code which works with any kind of object • Lists, maps, etc. Claytonia virginica
Features • Messaging - AYCDISAM • All you can do is send a message • Pass objects around • Modularity • Independent maintenance • Simplifies validation • Data-encapsulation • Facilitates re-use • Application Programmer Interfaces (APIs) Happy programmers are polymorphic A happy programmer
When to use OO? • Large software because it’s extremely good at: • Managing complexity • Facilitating flexibility • Maintainability • Design patterns are common solutions to common problems • Specifically developed and appropriate to OO • For small stuff do whatever you want • Many features are common to procedural languages, just done with more style
Thank You! • Resources • http://java.sun.com/docs/books/tutorial/java/concepts/ • http://en.wikipedia.org/wiki/Object_oriented • http://en.wikipedia.org/wiki/Procedural_programming • http://www.paulgraham.com/reesoo.html • Critique of OO: http://www.paulgraham.com/noop.html