summaryrefslogtreecommitdiff
path: root/pages/develop/tutorials
diff options
context:
space:
mode:
authorXavi Artigas <xavierartigas@yahoo.es>2018-05-25 10:25:14 -0700
committerapache <apache@e5-web1.enlightenment.org>2018-05-25 10:25:14 -0700
commit229a4bcb9f2dc4baac849a48cbcade29dfbc311e (patch)
treee4f181f7193dc3bd0bb909021dc98b608a42139d /pages/develop/tutorials
parente3b76d53c36c5ddb38bf03bb6ccac5e5d941098c (diff)
Wiki page eo-inherit.md changed with summary [] by Xavi Artigas
Diffstat (limited to 'pages/develop/tutorials')
-rw-r--r--pages/develop/tutorials/c/eo-inherit.md.txt18
1 files changed, 10 insertions, 8 deletions
diff --git a/pages/develop/tutorials/c/eo-inherit.md.txt b/pages/develop/tutorials/c/eo-inherit.md.txt
index f1be273a0..c980049de 100644
--- a/pages/develop/tutorials/c/eo-inherit.md.txt
+++ b/pages/develop/tutorials/c/eo-inherit.md.txt
@@ -5,7 +5,7 @@
5 5
6# Class Inheritance with Eolian # 6# Class Inheritance with Eolian #
7 7
8The [Creating New Classes](eo-classes.md) tutorial explained how to define new classes using Eolian. New classes don't need to start from scratch however. In fact, it is common practice in *Object Oriented Programming (OOP)* to extend the functionality of an existing class by *inheriting* from it and creating a new one. 8The [Creating New Classes](eo-classes.md) tutorial explained how to define new classes using Eolian. New classes don't need to start from scratch however. In fact, it is common practice in [Object-oriented programming](https://en.wikipedia.org/wiki/Object-oriented_programming) (OOP) to extend the functionality of an existing class by *inheriting* from it and creating a new one.
9 9
10This tutorial shows how to inherit from a class in Eolian. It also describes how derived classes can access their parent's public and private data. 10This tutorial shows how to inherit from a class in Eolian. It also describes how derived classes can access their parent's public and private data.
11 11
@@ -31,7 +31,7 @@ class Example.Square (Example.Rectangle) {
31} 31}
32``` 32```
33 33
34As you can see this is derived from ``Example.Rectangle``. Regular classes must be derived from ``Efl.Object`` but in this case you get that automatically, since ``Example.Rectangle`` already is already derived from ``Efl.Object``. 34As you can see this is derived from ``Example.Rectangle``. Regular classes must be derived from ``Efl.Object`` but in this case you get that automatically, since ``Example.Rectangle`` is already derived from ``Efl.Object``.
35 35
36You can also notice that this class does not provide any new method or property (there is no ``methods`` block). It only implements two properties, which currently belong to its parent class (``Example.Rectangle.width`` and ``Example.Rectangle.height``). Furthermore only the setters for these properties are implemented: Reads of these properties will be routed to the getter in the parent class. 36You can also notice that this class does not provide any new method or property (there is no ``methods`` block). It only implements two properties, which currently belong to its parent class (``Example.Rectangle.width`` and ``Example.Rectangle.height``). Furthermore only the setters for these properties are implemented: Reads of these properties will be routed to the getter in the parent class.
37 37
@@ -59,7 +59,9 @@ The implementation of these methods requires calling the parent class, therefore
59#include "example_rectangle.eo.h" 59#include "example_rectangle.eo.h"
60``` 60```
61 61
62You now need to focus on implementating these setters. They both need to set the ``width`` and ``height`` internal variables to the same value. These variables are private to ``Example.Rectangle``, so ``Example.Square`` has no direct access to them. These can be accessed through the setters from ``Example.Rectangle`` however. The setter has not been called from the ``Example.Square`` currently being implemented, as this would create an infinite loop. 62You now need to focus on implementing these setters. They both need to set the ``width`` and ``height`` internal variables to the same value. These variables are private to ``Example.Rectangle``, so ``Example.Square`` has no direct access to them. However, they can be modified through the setters from ``Example.Rectangle``.
63
64A small caveat, though: The parent's setters are being overridden by the derived class, so if you try to call them directly from the overridden code, you will end up in an infinite loop! Keep reading.
63 65
64In EFL when you need to call a method from your parent instead of your overridden version you can use ``efl_super()``. Its first parameter is the object and the second is *the class whose parent you want to call*. Write these implementations for the setters and all will become clear: 66In EFL when you need to call a method from your parent instead of your overridden version you can use ``efl_super()``. Its first parameter is the object and the second is *the class whose parent you want to call*. Write these implementations for the setters and all will become clear:
65 67
@@ -106,7 +108,7 @@ _square_create()
106{ 108{
107 Example_Square *square; 109 Example_Square *square;
108 110
109 square = efl_add(EXAMPLE_SQUARE_CLASS, NULL, 111 square = efl_new(EXAMPLE_SQUARE_CLASS,
110 efl_name_set(efl_added, "Square"), 112 efl_name_set(efl_added, "Square"),
111 example_rectangle_width_set(efl_added, 7)); 113 example_rectangle_width_set(efl_added, 7));
112 114
@@ -137,7 +139,7 @@ Next call ``_square_create()`` and print some information, immediately after doi
137 139
138Notice how you only used ``Example.Rectangle`` methods here because ``Example.Square`` inherits from it. All methods that work on a rectangle also work on a square. 140Notice how you only used ``Example.Rectangle`` methods here because ``Example.Square`` inherits from it. All methods that work on a rectangle also work on a square.
139 141
140Remember to dispose of your objects using ``efl_unref()`` if you do not give them a parent in ``efl_add()``. 142Remember to dispose of your objects using ``efl_unref()``. Alternatively, you could give them a parent using ``efl_add()`` instead of ``efl_new()`` and let the parent handle object disposal.
141 143
142The main program (``eo_inherit_main.c``) should now look like this: 144The main program (``eo_inherit_main.c``) should now look like this:
143 145
@@ -155,7 +157,7 @@ _rect_create()
155{ 157{
156 Example_Rectangle *rectangle; 158 Example_Rectangle *rectangle;
157 159
158 rectangle = efl_add(EXAMPLE_RECTANGLE_CLASS, NULL, 160 rectangle = efl_new(EXAMPLE_RECTANGLE_CLASS,
159 efl_name_set(efl_added, "Rectangle"), 161 efl_name_set(efl_added, "Rectangle"),
160 example_rectangle_width_set(efl_added, 5), 162 example_rectangle_width_set(efl_added, 5),
161 example_rectangle_height_set(efl_added, 10)); 163 example_rectangle_height_set(efl_added, 10));
@@ -168,7 +170,7 @@ _square_create()
168{ 170{
169 Example_Square *square; 171 Example_Square *square;
170 172
171 square = efl_add(EXAMPLE_SQUARE_CLASS, NULL, 173 square = efl_new(EXAMPLE_SQUARE_CLASS,
172 efl_name_set(efl_added, "Square"), 174 efl_name_set(efl_added, "Square"),
173 example_rectangle_width_set(efl_added, 7)); 175 example_rectangle_width_set(efl_added, 7));
174 176
@@ -233,7 +235,7 @@ In ``example_rectangle.c``, replace the structure with an include :
233#include "example_rectangle_private.h" 235#include "example_rectangle_private.h"
234``` 236```
235 237
236Finally include the header from ``example_square.c`` too. At this point the implementation for ``Example.Square`` can interpret its parent's private data ``Example.Rectangle``. You only need to retrieve a pointer to that data using ``efl_data_scope_get()``. This is how your square setters should look now: 238Finally include the header from ``example_square.c`` too. At this point the implementation for ``Example.Square`` can interpret its parent's private data ``Example_Rectangle_Data``. You only need to retrieve a pointer to that data using ``efl_data_scope_get()``. This is how your square setters should look now:
237 239
238```c 240```c
239EOLIAN static void 241EOLIAN static void