You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: Chapters/PharoObjectModel/Traits.pillar
+3-4
Original file line number
Diff line number
Diff line change
@@ -410,20 +410,19 @@ You can also access the overridden methods by creating an alias associated with
410
410
Traits define methods and instance variables.
411
411
Traits can be considered as kinds of class ''fragments''.
412
412
As such they cannot be directly instantiated.
413
-
Traits are used by classes whose instances have the state and behavior of the trait.
413
+
Traits are used by classes whose instances gain the state and behavior of the trait.
414
414
415
-
In addition a trait is not meant to be subclassed. Inheritance will not work.
415
+
In addition a trait is not meant to be subclassed. Inheriting from a trait will not work.
416
416
A trait, however can be reused by other traits. We say it can be composed out other traits.
417
417
418
418
So we get a world where:
419
419
- Classes can be extended by inheritance. Class can use traits.
420
420
- Traits are reused by classes and other traits. There is no inheritance between traits only composition.
421
421
422
-
423
422
If two classes (using different traits defining a method with the same name such as ==fly== in our example) are in an inheritance relationship, the method lookup works are normal: it works as if the traits would not exist and the methods would be defined directly in the classes.
424
423
425
424
Let us imagine that ==Bird== uses ==TFlyingAbility==, ==Eagle== uses ==THighFlyingAbility==, and ==Eagle== inherits ==Bird==.
426
-
An instance of ==Eagle== will execute the method fly from ==THighFlyingAbility== or its local redefinition if it was locally redefined by the class.
425
+
An instance of ==Eagle== will execute the method ==fly== from ==THighFlyingAbility== or its local redefinition if it was locally redefined by the class.
0 commit comments