Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RFC: Modify ZigBeeNodeListener #690

Open
cdjackson opened this issue Jul 21, 2019 · 5 comments
Open

RFC: Modify ZigBeeNodeListener #690

cdjackson opened this issue Jul 21, 2019 · 5 comments
Labels
breaking change enhancement pinned Will not be closed, even if stale
Milestone

Comments

@cdjackson
Copy link
Member

Currently the ZigBeeNodeListener interface contains method for nodeAdded, nodeUpdated and nodeRemoved. It has been proposed in #649 to add a new nodeDiscovered method to be called when node discovery information changes.

I'm a little wary of adding new methods each time we want to notify of something new, and instead propose to change the interface to have a single method, and an enumeration stating the reason for the notification.

eg -:

nodeListener(ZigBeeNodeListenerNotification notification, ZigBeeNode node);

ZigBeeNodeListenerNotification {
    /*
     Node has been added to the network
     */
    ADDED,

    /*
     Node discovery data has been updated. This includes new endpoints or clusters being added to the node.
     */
    DISCOVERED,

    /*
     Node has been updated. This includes any changes to information such as routes and neighbours.
     */
    UPDATED,

    /*
     Node has been removed from the network
     */
    REMOVED
}

I do welcome comments on this approach versus the option of simply adding new methods.

@triller-telekom
Copy link
Contributor

Sorry for the late reply.

To me this sounds like a reasonable approach. Plus point of this approach is that we have to break the API now once and afterwards we can simply extend this enumeration to introduce further reasons for notifications.

@cdjackson cdjackson added this to the 1.3.0 milestone Aug 11, 2019
@cdjackson cdjackson added the pinned Will not be closed, even if stale label Oct 6, 2019
@cdjackson cdjackson modified the milestones: 1.3.0, 1.4.o, 1.4.0 Nov 14, 2019
@mikomarrache
Copy link
Contributor

Not having to rely on enums is generally a better approach. Enums introduce all sort of problems (client code may rely on ordinals, enum names, etc) while we don't get such issues using methods. For example, if I store the events triggered by this listener in a database, I would use the ordinal or the enum name. If enum order or entries names change, that would break client code (though client code still compiles).

Also, adding a method to an interface doesn't break the API as long as the method is declared as default (in this case with a no-op implementation).

I would go with the new method approach.

@cdjackson
Copy link
Member Author

We already rely on enums in other listeners such as the network state listener, and there is quite extensive use of enums throughout the framework. If we never used enums for notifications, we'd have a lot of methods so the problem is it's not scalable IMHO.

If a user is importing the framework, then the enum is available, and it's generally not recommended to use the ordinal on enums in any case as this can always change - again this would be the same if you use the current enums.

@mikomarrache
Copy link
Contributor

We already rely on enums in other listeners such as the network state listener, and there is quite extensive use of enums throughout the framework. If we never used enums for notifications, we'd have a lot of methods so the problem is it's not scalable IMHO.

Indeed enums are used throughout the framework but I was thinking about possible direction change for new or refactored code.
I'm not sure what you mean by scalability here? In terms of scalability, adding enum entries or default methods is similar.

If a user is importing the framework, then the enum is available, and it's generally not recommended to use the ordinal on enums in any case as this can always change - again this would be the same if you use the current enums.

Indeed, it's not recommended to use the ordinal on enums, but then you are left with the enum names. And you get exactly the same issue, changing the name of an enum entry may break existing code that still compiles. That's why you often see code that defines another "code" property at the enum level which never changes. This way enum entries order can be changed (i.e. ordinal changes) or renamed, but the code is left untouched.

Another point to take into account is that you may want to provide all sort of information that may depend on the type of event. Using methods, every listener method may have a different signature. With enums, that is not the case.

I just got into this ticket and I thought that would be good to give my two cent for this wonderful project.

@cdjackson
Copy link
Member Author

I'm not sure what you mean by scalability here?

I mean if each listener had 5 or 10 different notifications, then you end up with a lot of methods being implemented.

changing the name of an enum entry may break existing code that still compiles.

Sure - but that's the same with changing method names. In general we try and avoid breaking changes to any external API such as changing enum names, or method names. I don't see that this is any different either way.

Another point to take into account is that you may want to provide all sort of information that may depend on the type of event.

Fair point, but that's not what we're really talking about. We have listeners that notify about one thing - eg the network state, or the node state. They pass information about that event - we're not using a single callback to provide very different information.

I just got into this ticket and I thought that would be good to give my two cent for this wonderful project.

Of course, and it's absolutely appreciated - it's good to have a debate which is why I try and raise these sort of issues here. Often I just "talk to myself" but getting other views is definitely useful and appreciated 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking change enhancement pinned Will not be closed, even if stale
Projects
None yet
Development

No branches or pull requests

3 participants