[Oberon] FPGA - Simple OOP example
joerg.straube at iaeth.ch
Tue Aug 14 22:39:48 CEST 2018
As you said in one of your previous mails: there are different ways to do OOP in Oberon. My recommendation to separate data and methods (and collect all methods in an own RECORD) has basically two reasons:
1) Space. It’s perhaps not so obvious in your Term example, but if you have objects like e.g. Figures, Circles, Rectangles ... you might have a large amount of methods (Draw, Fill, Rotate, Delete, Move, Shrink, Recolor...) . Let’s assume you prgram a game and your background landscape is composed of 1000s of Figures. And every Figure does not only store its data like radius and color but also all methods as well, the space in memory for all those objects is quite large. After all, keep in mind all the methods in all Figures point to the same procedures it‘s just a waste of memory to store the methods separately again and again in every figure.
2) Consistency. If you have a Figure like a Circle, there might be 100 different instances of circles. The local data that is different per circle (Big, small, red, blue, filled...) is stored and varies per instance. But you expect that all circles behave the same. So it makes sense to collect the behaviour (=its methods) of the object „Circle“ in an own RECORD. And let all different instances of object Circle point to the one same behaviour.
> Am 14.08.2018 um 19:48 schrieb Tomas Kral <thomas.kral at email.cz>:
> Jan, Joerg,
> Thank you, recoding my example now. Just curious, is there a specific
> reason to keep object's data from its methods?
> Tomas Kral <thomas.kral at email.cz>
> Oberon at lists.inf.ethz.ch mailing list for ETH Oberon and related systems
More information about the Oberon