Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to design an extensible type infrastructure with dependencies among each other
    primarykey
    data
    text
    <p>My application is an editor for connecting "modules" (through module ports). Ports have port types. Each port type has it's associated comparator. Two types are compatible if their attributes satisfy rules implemented in the comparator.</p> <p>I want users to extend the application by implementing new port types and rules how to connect them (through the eclipse extension point infrastructure).</p> <p>This implies that during runtime I can only interact with the port type interfaces. No concrete classes are known. All concrete implementations are returned by a factory.</p> <p>I implemented this two interfaces:</p> <pre><code>public interface IPortType { [many attributes] } public interface IComparator { public boolean isCompatible(IPortType source, IPortType target); // more interaction methods! } </code></pre> <p>My current solution is a bit ugly, since the generic isCompatible(IPortType source, IPortType target) method is a kind of delegate and has to be rewritten in all subclasses. Simply overloading the isCompatible() method does not work here.</p> <p>But a bigger disadvantage is the violation of the open-closed-principle: One must extend all concrete Comparator classes when a new type should be supported. But how to keep the number of <em>rule classes</em> low, when there are more interactions between types like conversion, etc.? My intention was to keep all rules for one type in one class.</p> <p>A concrete Comparator example:</p> <pre><code>public class ATypeComparator implements IComparator { public boolean isCompatible(IPortType source, IPortType target) { if (!(source instanceof AType)) return false; if (target instanceof BType) return isCompatible(source, (BType) target); if (target instanceof CType) return isCompatible(source, (CType) target); } public boolean isCompatible(AType source, BType target) {...} public boolean isCompatible(AType source, CType target) {...} } </code></pre> <p>How would you solve this problem?</p> <p>Thanks for any suggestions!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload