formations/algo/poo/cours/mechanism.txt

91 lines
3.9 KiB
Plaintext

Mechanismes objets
===================
L'impossible définition
------------------------
- ObjectsAreDictionaries - maps that can readily contain "function pointers" or function containers, with language and/or syntax features that assist in or simplify the usage of these function maps.
Variation: "objects are maps that can map interfaces and/or references to other such maps."
- OO is the view that EverythingIsa a behavior (including data structures)
- OO is the "natural extension" of programmer-defined types (sometimes known as user-defined types).
- Inheritance + Encapsulation (no polymorphism): "Inheritance is what separates abstract data type (ADT) programming from OO programming." Section 19.1 of the Feb 2000 Usenet C++ FAQ, which is also published in expanded form in a popular and influential book. Inheritance without polymorphism, however, is little more than compiler-assisted CopyAndPasteProgramming. Useful, but OO?
Pour être qualifié de Orienté Objet, un langage doit être **pur**.
.. glossary::
langage pur
Langae dans lequel tout est objet. Exemples : smalltalk, python
Les trois grandes qualités
- We should stop using the term "Object Oriented".
- plusiers définitions : http://wiki.c2.com/?DefinitionsForOo
- on ne peut pas en choisir une seule : http://wiki.c2.com/?NobodyAgreesOnWhatOoIs
- class based programming
In a class-based language (like JavaLanguage or SmalltalkLanguage), every object is an instance of a class. An object contains its own data (instance variables), but its class holds its behaviour (methods). To make a new object, you ask a class to "instantiate" itself.
An Object Oriented system, language, or environment should include at least Encapsulation, Polymorphism, and Inheritance.
There is a largely accepted definition of OO: roughly the style encouraged by
Java (classes, encapsulation, inheritance, subtype polymorphism, and even
sometimes genericity).
https://en.wikipedia.org/wiki/Class-based_programming
encapsulation
--------------
- d'attributs
- de méthode (exposer une interface mais on ne sait pas comment cette interface est codée)
Delegation
Than please define what you think delegation is. Let's start with something concrete:
If the method call:
targetObject.method(x1,x2,...,x_n)
Is then resolved in the body of TargetClass.method() to:
delegate.method(x1,x2,...,x_n)
Yet another reason is the popularity of languages that brand themselves "OO".
C++, Java, Python, Javascript, Self… New ones pop up daily. That doesn't help
define "OO", but it does makes it ever more present.
La liaison retardée
-------------------
Internal polymorphism is the kind of polymorphism that you see in most OO computer languages. When you call a method on an object the actual function called is based on the dynamic type of the object.
Prototypes
----------
A prototype is an object that is used as a template to create other objects. 2 mechanisms are used for this: copy and delegation. When creating a derived object from a prototype, you can copy part of the prototype. The part that isn't copied can still be accessed through a delegation pointer stored in the derived object. When you try to access a member of the derived object, and it isn't there, we walk up the delegation pointer to ask the prototype instead.
Prototype based programming have lots of interesting implications, that I have no experience with. I don't know how if it helps you write shorter or more modular code, especially compared to other mechanisms. I will just note that prototypes are easily implemented (or emulated) in any dynamic language with first class functions and associative maps.
https://en.wikipedia.org/wiki/Prototype-based_programming
In a prototype-based language, an object can contain both data and behaviour. It's a self-contained thing. To make a new object, you just call the "copy" method on an existing object.
http://wiki.c2.com/?PrototypeBasedProgramming