Skip to content

Use constructors for WoT objects #3

Closed
@zolkis

Description

@zolkis

Since WoT is going to be implemented on different types of runtimes (see also #2),
and since the root [1] WoT object has no state,
arguably it would be simpler to expose the WoT object with a constructor (internally implementations could still use a singleton).
Also, for ExposedThing and ConsumedThing we could provide constructors instead of factories. That would be more aligned with ECMAScript best practices (e.g. an ExposedThing object could be created for testing purposes, shaped locally, then exposed).

Currently the interface uses factories:

interface WoT {
    Promise<void>          discover(ThingFilter filter,
                                    ThingDiscoveryCallback onfound);

    Promise<ConsumedThing> consumeDescription(object thingDescription);
    Promise<ConsumedThing> consumeDescriptionUri(DOMString thingDescriptionURI);

    Promise<ExposedThing>  createThing(DOMString name);
    Promise<ExposedThing>  createFromDescription(object thingDescription);
    Promise<ExposedThing>  createFromDescriptionUri(DOMString thingDescriptionURI);
};

It could be changed into:

[Constructor()]
interface WoT {
    Promise<void>          discover(ThingFilter filter,
                                    ThingDiscoveryCallback onfound);
};

[Constructor(DOMString name)]
[Constructor(object ThingDescription)]
[Constructor(DOMString thingDescriptionURI)]
interface ExposedThing {
  // ... 
 Promise<void> expose();  // register with the WoT network
};

[Constructor(object ThingDescription)]
[Constructor(DOMString thingDescriptionURI)]
interface ConsumedThing {
  // ... 
  Promise<void> fetch();  // retrieve/validate the Thing
};
 

[1] edited: s/Wot object/root WoT object

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions