-
Notifications
You must be signed in to change notification settings - Fork 361
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
could Visitor pattern be usefull for configuration in Cf? #1601
Comments
My idea about a redesign of the configuration was to move common parts to element-connector and to extend that by the specific components (e.g. DTLS or TCP). Potentially also "network-interface" specific. I'm not sure, which advantage the visitor pattern brings. Though some upstream projects will depend on that, I would try to get feedback from them as well. @sbernard31 (leshan) WDYT? Short feedback will be welcome. |
The main advantage of the Visitor pattern is that the structure of the configuration itself is decoupled from components that use it internally. Different components can have their own view on (a part of) the configuration and don't have to 'know' its structure. This 'knowledge' is delegated to the visitor which extracts the needed configuration items. The structure of the configuration can be focused on ease of use (from application developer perspective), without imposing this structure on the internal components of Californium / Scandium. Different visitors can be defined for different purposes. Because of the way Mule SDK works, I had to define configuration classes containing Mule annotations. These classes are scanned by Mule using reflection and are not allowed to depend on Californium classes. So, decoupling using the Vistor pattern was needed there. Could very well be that it isn't worth the effort in other usecases... |
So, in any case, someone needs to know the structure (and semantics) of the configuration in the end. I do not really see the value of introducing the visitor pattern here as a general means of processing the configuration properties. It is still possible to decouple Cf's NetworkConfig class from (application specific) views on it by letting your visitor process the whole NetworkConfig class and create your application specific view from it (as @rogierc already seems to have done for Mule). I do not think that we need it internally to create Cf components as the configuration properties do not tend to change that often, or do they @boaks? |
The The main pain on my side was, that this is located in the |
Would that decouple NetworkConfig from the classes being configured. Will users wil get specific classes/interfaces/builders to configure different components like endpoints and connectors? One problem now is - I think - that NetworkConfig contains configuration for all these different components. That does not help the user with what configuration items need to be set for his use case. (the endpint/connector in use). Also items are not typesafe in NetworkConfig. The user has to check the component that get configured to know which configuration items are needed and what their type is. The goal of the visitor pattern is not only to improve maintainability, but also being able to give the user a convenient and helpfull information structure of configuration items that is not burdened with 'technicalities' of how configuration is processed (like: it needs to be stored in a file and therefore everything is a String). Sure, this goal could be achieved using the visitor pattern, and also with other means. The main goal is IMHO to improve the configuration experience for the user. |
At least, I don't plan that. I hardly see a benefit in that.
FMPOV, the main pain is, that NetworkConfig is in the core module. It has no means to be extended for different modules, nor can connector modules access it directly, because the design makes the core depending on the connectors, and not visa-verse. Moving a reduced NetworkConfig to the element-connector and provide a extension API would solve that pain. My current idea is still a general configuration, but the contained values are depend on the used and using module.
For me it seems to be somehow unclear, how users use that configuration. Editing the properties file? Prepare/adjust the config in code? My impression is, that it is much harder to know, what the "property does" (and knowing that, makes the type in many cases obvious), than to find out, which type is used. The purpose is too often bound to specification details and not that easy to understand. The only good thing is, that in many cases the defaults will do it and there is no general need to adjust them. In my sum up:
|
In Leshan library we prepare/adjust config in code. My feedback about the design : My feedback as a user about current As a user It would be OK to me if I have several files(builder and properties) for configuration (like one for CoAP, one by connector, etc ...), but maybe this is possible to do have something clear with a unified config too. (harder to me to see how it could look like 🤔 ) HTH (a little bit 😬) |
(I'm a bit out of topic as my comment is not really related to the visitor pattern but this is more generics remarks about config redesign) |
The Visitor question is about which way to go forward with config redesign. So I don't think it's of topic. ;-) |
This class, that deals with 'everything' on one side and the different configuration items, builders and components that get configured on the other side, need to be loosely coupled. For maintainability reasons, but also because of different responsibilities. When not loosely coupled the designs need to account for responsibilities of other classes, need to be a compromise and will propably be less comfortable for the user. The Visitor pattern is one way to realise loosely-coupled-ness. When not using this pattern which other design could be considered? (Haven't looked into #1648 yet.). Or is loosely-coupled-ness not considered needed here at all? IMHO, the observations of @sbernard31 are symptoms of too much compromise in the design:
|
My feeling is, a central point as AbstractConfigVisitor would require to be adapted for too many cases. My current idea is still very close to I still think, that the view on the "right way" depends much on the way using it. Many people are just changing the value in Californium.properties, they don't adjust the values in their code. And those, who adjust the values in their code, would all love to have it done in their way. Unfortunately, only "one way" could be implemented, all others have to implement and maintain their glue- and converter-code. |
I don't plan to adapt the new configuration to the "visitor pattern". |
Feel free to comment, if this issue should be opened again. |
The Mule Coap connector has a set of configuration classes to define the CoAP servers, clients and CoAP endpoints to use in the Mule application. These classes organise all configuration-parameters in a logical structure to give the application developer a good user-experience.(Mule's development environment enables configuration in it's GUI using java-reflection). The Visitor design pattern is used to separate the configuration classes, that are structured for ease of use, from the proces of building Cf entities such as different types of endpoints and connectors.
Maybe this approach is usefull for Californium also. To explore this idea, I've put the configuration classes in a Cf-fork and removed Mule particulars. See: config package
The package contains an usage-example also. It shows how different visitors can be used to construct CoAP servers with different endpoint types. The visitors sub-package contains also the NetworkConfigGetVisitor and NetworkConfigSetVisitor that convert the new configuration-classes to or from the good old NetworkConfig.
The solution probably isn't complete but maybe enough to assess feasability of the idea.
The text was updated successfully, but these errors were encountered: