If I need a custom string representation of custom type collection, which is the best option - the collection is sub-class and ToString override (), or just create a utility method that takes custom typed compilation and gives a custom string? What is another option?
I would have to make a utility method. There are some reasons:
- Logically, your custom string representation is something that you are leveraging over the original class: it is not part of the original class. So this is not within the definition of the original class.
- Creating a subclasses is probably overkill for overriding a method
- Creating a custom subclass makes it impossible to work with an object that overrides the original class for a different reason Used to be. If you use heritage for things like this, you can easily mismatch in succession. Always like the structure of heritage!
- You can continue to use the original
toString () for a few reasons: You probably need both string convergence or any other library depends on the original code
You have one more option within the "Utility System" option: P>
- Make a simple static utility method simple, quick, this may be your first choice.
- Create a "formatter" object with a method like
No comments:
Post a Comment