-
Notifications
You must be signed in to change notification settings - Fork 0
Suggested API #6
Comments
In rometools/rome#353 @buko said:
I'm not sure I understand the difference between a builder and a factory from DI perspective. I mean, in case of a builder wouldn't you build the object beforehand and inject an already built object? |
About the comment from @buko I don't think that builders are an antipattern and configurable factories should be preferred, builders are configurable factories with the factory method Generally, builders are used to create a (more or less) complex instance of a concrete class, where as a factory may create different implementations. Like tl;dr If you want to create immutable instances of a concrete class, call it |
Some questions or paraphrasing about the interface to be sure I'll get it right:
|
@imk You got everything right, that's how I see it. The difference between Itunes and yahoo comes from me pretending that yahoo is an external plugin supplied by the user. The
Not sure if I don't know much about Not sure how to solve inconvenience with updating an immutable object. Maybe something like this? Feed feed = rome.read(data);
Feed.Builder feedBuilder = feed.toBuilder(); // Converts whole object tree to builders
List<Item.Builder> items = feedBuilder.items(); // Items are actually builders now
items.forEach(item -> item.title("test")); // Update titles
Feed feed2 = feedBuilder.build(); // Builds whole object tree Or we could provide a Feed feed2 = feed.map(builder -> builder.items().forEach(item -> item.title("test"))); |
@mishako that's looking good, should work that way! 👍 |
Doesn't seem to be controversial. Let's try it out in the prototype. I'm closing the ticket. |
Main ideas:
The entrypoint is class
Rome
with only two methods:Engine.Builder
is used for configuration. For example:Now when you have a configured
Engine
you can read a feed:StringValue
andDateTimeValue
are wrappers aroundString
andDateTime
. They have additional information attached, e.g. raw values, parsing errors, location in the XML.To write a feed you build it and pass it to your
Engine
:See more examples in my gist.
The text was updated successfully, but these errors were encountered: