owlcs / owlapi

OWL API main repository
822 stars 315 forks source link

Changes in API-interfaces regarding return types #1034

Open sszuev opened 2 years ago

sszuev commented 2 years ago

I think, it would be better to replace all the concrete modifiable classes from interfaces with interfaces as well. Basically, it's about the return types mentioned in the org.semanticweb.owlapi.model.OWLOntologyManager, i.e. about the followings:

I think this also would be more correct in terms of architecture\design: it is better when interface methods do not return mutable non-final concrete classes.

In order not to interfere with the current client code, this could be done somewhere in version 5.2+ v6.x.x, I think, implies more deep changes, while these proposed changes may not be even visible to end-users (to notice, it is need to have code calling constructors directly). And also, generally speaking, it would be better to make a generic mechanism to retrieve\set configuration that would not depend on implementation at all.


Originally it was posted here: https://github.com/orgs/owlcs/teams/ontapi-contributors/discussions/1

ignazio1977 commented 2 years ago

a generic mechanism to retrieve\set configuration that would not depend on implementation at all

I like that idea. What would this look like?

sszuev commented 2 years ago

I was thinking of something like this:

    interface OWLOntologyManager {
        OntologyConfig getOntologyConfigurator();
    }
    interface OntologyConfig {

        OntologyConfig setBoolean(Key key, boolean value);

        boolean getBoolean(Key key);

        @Deprecated // ?
        default OntologyConfig setAcceptingHTTPCompression(boolean b) {
            return setBoolean(OWLAPISettings.BOOLEAN_ACCEPT_HTTP_COMPRESSION, b);
        }

        @Deprecated // ?
        default boolean shouldAcceptHTTPCompression() {
            return getBoolean(OWLAPISettings.BOOLEAN_ACCEPT_HTTP_COMPRESSION);
        }

        interface Key {
        }
    }
    enum OWLAPISettings implements OntologyConfig.Key {
        BOOLEAN_ACCEPT_HTTP_COMPRESSION,
    }

I think, such a configuration should be much easier to override and extend across implementations. (to be more specific, I should probably prepare a PR ?)

ignazio1977 commented 2 years ago

Why not simplify further and just have a Map<String, Object>? ConfigurationOptions can act as the list of known properties and be easily adapted to expose the property name (it already has that information to look up properties from property files and system properties), and any implementations specific property can be added without impact. ConfigurationOptions would just be there for defaults and to avoid mistyping property names.

sszuev commented 2 years ago

Why not simplify further and just have a Map<String, Object>? ConfigurationOptions can act as the list of known properties and be easily adapted to expose the property name (it already has that information to look up properties from property files and system properties), and any implementations specific property can be added without impact. ConfigurationOptions would just be there for defaults and to avoid mistyping property names.

I think that wouldn't be very user-friendly:

But on the other hand, I agree that the configuration management code is overly complicated, and switching to use java.util.Map would partially solve this problem.