Rationale behind lack of object composition? #95
Replies: 1 comment 6 replies
-
Actually, what most OOP languages allow is objects to contain references to other objects. The language syntax may provide an appearance of objects being able to contain other objects. But that's essentially syntactic sugar.
As you noted, that's a different feature: multiple namespaces. Logtalk currently provides single namespace for objects, protocols, and categories. Although I played and even prototyped an implementation of multiple namespaces, never found a satisfactory design and solution.
Logtalk objects are indeed designed to encapsulate predicate directives and predicate definitions (clauses). But nothing prevents an object of containing a clause where arguments are references to other objects. That's illustrated by several examples bundled with the Logtalk distribution (see e.g. the
Have you looked into the design patterns sample implementations?
Could the technical solutions illustrated by this blog post be useful in your case? |
Beta Was this translation helpful? Give feedback.
-
Hello,
We are wondering what is the design rationale behind's Logtalk's absence of a containment relationship between objects. Most object-oriented languages (e.g., UML, Java, JavaScript) allow an object to contain other objects. In addition, they also allow grouping classes or objects into packages (or modules in the case of JavaScript). So those OO languages allow the developer to express multiple levels of encapsulation like Russian dolls.
In contrast, Logtalk seems to only offer a single level of encapsulation: clauses into objects or category and that's it. There is no language construct to further encapsulate those clause encapsulating entities into higher granularity container entities.
This seems to us to be a limitation for "programming in the large". For example, it would be convenient to encapsulate all the entities constituting a library into a reusable component implementing a protocol but distributing (delegating) the responsibilities of this implementation among multiple entities encapsulated inside the component (as in a UML Structured Classifiers). As far as we understand, in the current version of Logtalk, a library is just a flat set of entities scattered in a set of files that by convention gets loaded by a loader file, but they no Logtalk language construct for that and hence no benefit from associated reflection and meta-programming built-in entities or predicates. For example, we would like to be able to pass a whole reusable library as parameter to an object or predicate for code analysis or transformation purposes.
Is there something specific about the declarative logic programming context of Logtalk, that we have not understood, that motivated this design choice?
Thanks for insights on this topic.
Beta Was this translation helpful? Give feedback.
All reactions