méchanismes objets
This commit is contained in:
parent
baab6fdd1f
commit
0d2e9732b3
|
@ -0,0 +1,26 @@
|
|||
Fermetures
|
||||
-----------
|
||||
|
||||
.. glossary::
|
||||
|
||||
fermeture
|
||||
|
||||
Dans un langage de programmation, une fermeture ou clôture (en anglais : closure) est une fonction accompagnée de son environnement lexical. L'environnement lexical d'une fonction est l'ensemble des variables non locales qu'elle a capturé, soit par valeur (c'est-à-dire par copie des valeurs des variables), soit par référence (c'est-à-dire par copie des adresses mémoires des variables)1. Une fermeture est donc créée, entre autres, lorsqu'une fonction est définie dans le corps d'une autre fonction et utilise des paramètres ou des variables locales de cette dernière. cf : https://fr.wikipedia.org/wiki/Fermeture_(informatique)
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
>>> def start_at(x):
|
||||
... def increment_by(y):
|
||||
... return x + y
|
||||
... return increment_by
|
||||
...
|
||||
>>> closure1 = start_at(1)
|
||||
>>> closure2 = start_at(2)
|
||||
>>> closure1(1)
|
||||
2
|
||||
>>> closure2(1)
|
||||
3
|
||||
|
||||
|
||||
With closures, class based programming is syntactic sugar.
|
||||
https://en.wikipedia.org/wiki/Closure_(computer_programming)
|
|
@ -0,0 +1,90 @@
|
|||
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
|
||||
|
|
@ -9,15 +9,29 @@ Avant propos
|
|||
des objets. Tous les programmeurs les utilisent, peu savent vraiment de quoi il en retourne,
|
||||
et très peu nombreux savent définir le paradigme et les mécanismes objets correctement.
|
||||
|
||||
|
||||
|
||||
.. FIXME
|
||||
|
||||
Introduction
|
||||
~~~~~~~~~~~~
|
||||
|
||||
.. FIXME
|
||||
|
||||
.. glossary:: POO
|
||||
|
||||
La programmation orientée objet (POO), ou programmation par objet, est un
|
||||
paradigme de programmation informatique élaboré par les Norvégiens Ole-Johan
|
||||
Dahl et Kristen Nygaard au début des années 1960 et poursuivi par les travaux
|
||||
de l'Américain Alan Kay dans les années 1970. Il consiste en la définition et
|
||||
l'interaction de briques logicielles appelées objets ; un objet représente un
|
||||
concept, une idée ou toute entité du monde physique, comme une voiture, une
|
||||
personne ou encore une page d'un livre. Il possède une structure interne et un
|
||||
comportement, et il sait interagir avec ses pairs. Il s'agit donc de
|
||||
représenter ces objets et leurs relations ; l'interaction entre les objets via
|
||||
leurs relations permet de concevoir et réaliser les fonctionnalités attendues,
|
||||
de mieux résoudre le ou les problèmes. Dès lors, l'étape de modélisation revêt
|
||||
une importance majeure et nécessaire pour la POO. C'est elle qui permet de
|
||||
transcrire les éléments du réel sous forme virtuelle.
|
||||
|
||||
https://fr.wikipedia.org/wiki/Programmation_orient%C3%A9e_objet
|
||||
|
||||
|
||||
Objectifs de ce cours
|
||||
|
|
Loading…
Reference in New Issue