Skip to content

Commit 1e2fe1b

Browse files
committed
traits
1 parent cb9ff8e commit 1e2fe1b

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

Chapters/PharoObjectModel/Traits.pillar

+3-4
Original file line numberDiff line numberDiff line change
@@ -410,20 +410,19 @@ You can also access the overridden methods by creating an alias associated with
410410
Traits define methods and instance variables.
411411
Traits can be considered as kinds of class ''fragments''.
412412
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.
414414

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.
416416
A trait, however can be reused by other traits. We say it can be composed out other traits.
417417

418418
So we get a world where:
419419
- Classes can be extended by inheritance. Class can use traits.
420420
- Traits are reused by classes and other traits. There is no inheritance between traits only composition.
421421

422-
423422
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.
424423

425424
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.
427426

428427

429428
!!! Conclusion

0 commit comments

Comments
 (0)