Objects Vs. Dino-Fortran

Download Report

Transcript Objects Vs. Dino-Fortran

Why you should care about Object Orientation (OO)
Iñaki Serraller Vizcaino



Objectives
OO Vs. Procedural
Concepts






Objects
Classes
Inheritance
Polymorphism
Features
When to Use OO?
2
¡To turn you all into Java programmers!
To explain a different programming paradigm and
its possible applications
Which programming language do you use?
Bua Ha Ha Ha
3
Object Oriented
Procedural
Attribute / Field
Variable
Method
Procedure / Function
Message
Argument
Objects
Module / Pointer / Structure
Class
File
Package
Module
4
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
5

Object blueprints
A dog blueprint
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();
6

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
7

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
8

Messaging - AYCDISAM
 All you can do is send a message
 Pass objects around

Modularity
 Independent maintenance
 Simplifies validation


Happy programmers
are polymorphic
A happy programmer
Data-encapsulation
Facilitates re-use
 Application Programmer Interfaces (APIs)
9

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
10

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
11