Mechanismes objets =================== L'impossible définition ------------------------ Pour être qualifié de Orienté Objet, un langage doit être **pur**. .. glossary:: langage pur Langage dans lequel tout est objet. Exemples : smalltalk, python - We should stop using the term "Object Oriented". - plusieurs définitions : http://wiki.c2.com/?DefinitionsForOo - on ne peut pas en choisir une seule : http://wiki.c2.com/?NobodyAgreesOnWhatOoIs Quelques essais de définition technique : - Les objets sont des dictionnaires, des clefs-valeurs qui peuvent contenir des pointeurs sur des fonctions. Le reste n'est que sucre syntaxique. - Variante: "objects are maps that can map interfaces and/or references to other such maps." - OO is the view of **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." class based programming ------------------------ In a class-based language (like Python 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. les méthodes spéciales ---------------------- Les méthodes spéciales permettent de changer la manière dont Python réagit à certains opérateurs et accède aux attributs d’une instance. Les méthodes spéciales sont entourées de deux "__" 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