formations/algo/poo/cours/definition.txt

79 lines
2.7 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

Définitions
===========
Protocole à méta-objets
----------------------------
Principes ouverts, principes fermés.
exemple : les slots en python
expliquer le for en python : c'est parce que l'objet possède une méthode
__iter__
un objet avec des slots utilise moins de mémoire qu'un dict.
sinon, il en utilise plus
Termes
-------
.. glossary::
Abstraction
The details of the implementation are hidden in the object, and the external interface is just the set of publicly accessible methods.
Dynamic lookup
When a message is sent to an object, the method to be executed is determined by the implementation of the object, not by some static property of the program. In other words, different objects may react to the same message in different ways.
Subtyping
If an object a has all the functionality of an object b, then we may use a in any context where b is expected.
Inheritance
The definition of one kind of object can be reused to produce a new kind of object. This new definition can override some behavior, but also share code with its parent.
Open recursion
An object's methods can invoke another method in the same object using a special variable (often called self or this). When objects are created from classes, these calls use dynamic lookup, allowing a method defined in one class to invoke methods defined in another class that inherits from the first.
objet en python
>>> o = object()
>>> o.a = 1
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'object' object has no attribute 'a'
>>>
l'objet est l'objet de base, tous les autres objets héritent de cet objet
>>> class A: pass
...
>>> isinstance(A, object)
True
>>>
Five are structural:
Abstraction Representing reality in a simplified form by removing certain distinctions so that we can see the commonalities.
Class A generalised description of similar objects that share a common structure and behaviour.
Encapsulation Data and behaviour are defined within an object and separated from everything else, protecting the internal representation of the object.
Inheritance Allows the attributes and methods of one class to be based on another existing class.
Object An individual, identifiable item, either real or abstract, which contains information about itself and the descriptions of its manipulations.
Three are behavioural:
Message The process by which an object sends Passing information or invokes a method.
Method Accessing, setting or manipulating an objects information.
Polymorphism Different objects can respond to the same message and implement it appropriately.