-
Notifications
You must be signed in to change notification settings - Fork 12
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
Consider adding a builder class for elements/links #129
Comments
while it makes sense to follow a pythonic style. we don't want the apis of different language to be too different. let' think though.
--
Sent from my Android device with K-9 Mail. Please excuse my brevity.
|
Well, its a pattern, I have seen it in Java code, including libraries we are currently using in bridges. And its very prevalent in Rust. I would imagine it has been used quite a bit in C++ aswell. It just allows for an easier configuration of complex structures without needing to understand long constructors of objects. |
I have suggested this style of chained attribute setting for the client APIs before. Historically we have elected not to implement this pattern due to concerns over potential confusion for beginning students (not to mention the added complexity of managing different versions of the same functions or revamping the whole API). I am personally open to discussing it again for all the client APIs for a future release. |
Sure, which is why the Builder pattern exists, its a separate class entirely, while the existing class can keep its current state, offer a different way of handling object instantiating. I have seen a lot of "Builder" variants in various libraries recently and I just figured it would be worth considering for our uses. |
https://en.wikipedia.org/wiki/Builder_pattern
There is a lot of bridges code that looks like
or
I think it may be worth looking into a builder pattern for elements at least, and maybe for links/other structures.
It would look something like
This could be extended easily by adding more functions to the builder. This also could alleviate the requirement for students/users to specify the type of their generic element, by just doing a type inspection on the value, or let them explicitly pass the type to the builder, even as a function if that makes more sense. This ElementBuilder could also be configured to build any sort of Element, possibly using some sort of enum/state based approach so that the builder could handle any linked element appropriately.
The text was updated successfully, but these errors were encountered: