Replies: 1 comment
-
Yes. But not common. Note that when an object imports a category, the category public predicates become object public predicates (unless, of course protected or private import of the category is used).
Categories allows adding predicates to multiple objects without requiring (the use of) inheritance. I.e. without requiring those objects to be part of the same hierarchy. Think of categories as a functionally-cohesive set of predicates that provide a useful service that can be reused by multiple objects.
That's a common design pattern. Categories often provides abstract methods to objects, requiring the objects to fill-in the details. In your sample code, that means objects should define the P.S. There's an old (unpublished) paper on categories that you may find worth reading: https://logtalk.org/papers/categories_ecoop.pdf The paper is outdated (e.g. no mention of hot-patching using categories or the full set of allowed category relations) but still explains some key ideas. |
Beta Was this translation helpful? Give feedback.
-
Hi,
there are some questions about categories which I could not resolve via handbook:
The same protocol can be implemented by categories and objects? For example, a protocol is load and save, an XML processing object implements its way of load and save, a "ASCII" categorie to be used in may objects implements the basic file load and save
Regard this code:
Assume, the object (an xml processor) which imports this category implements the xml_out/1. Therefore the ::xml_out(Something) would call the method of self, which is an object_method, which is really there. The compiler accepts this construct, but I'm not sure if this would run reliable and if this is really good. Of course, the user of the category has to know that the importing object has to implement xml_out/1, which may be suboptimal ;)
Any thoughts?
Cheers
Hans
Beta Was this translation helpful? Give feedback.
All reactions