Jump to content

Overlays: Difference between revisions

1,205 bytes added ,  17 February 2019
Add section on data flow with illustration
imported>Danbst
No edit summary
imported>Dramforever
(Add section on data flow with illustration)
Line 12: Line 12:
};
};
</syntaxhighlight>
</syntaxhighlight>
== Data flow of overlays ==
The data flow around overlays, especially regarding <tt>super</tt> and <tt>self</tt> arguments can be a bit confusing if you are not familiar with how overlays work. This graph below hopefully illustrate the data flow better:
[[File:Dram-overlay-self-super.png]]
Here the main package set is extended with two overlays, ext-1 and ext-2. <tt>a // b</tt> is represented by a <tt>//</tt> box with <tt>a</tt> coming in from the left and <tt>b</tt> from above.
As you can see, <tt>self</tt> is the same for every stage, but <tt>super</tt> comes from only the stage before. So when you define an attribute <tt>foo</tt> in the set to override it, within that overlay <tt>self.foo</tt> will be it's version, and <tt>super.foo</tt> will be the non-overriden version. This is why you see patterns like <tt>foo = super.foo.override { ... }</tt>.
The names <tt>self</tt> and <tt>super</tt> might remind you of inheritance in object-oriented languages. In fact, overlays are exactly the same thing as subclasses, with regards to overriding and calling methods. This data flow is also how objects know which method to call. This is probably why the two arguments got their names, too.


=== Applying overlays manually ===
=== Applying overlays manually ===
Anonymous user