I'm building an RSS client and using the Argotic framework. It provides different classes for different kinds of feeds like Atom, RSS, and OPML. These classes don't inherit from any other class and they don't implement a common interface for accessing their properties.
There is a GenericSyndicationFeed
type that implements an overloaded method where you can pass in an AtomFeed
or RssFeed
. If I want to use the "more" strongly typed classes I would essentially need two code paths (one for Atom and one for RSS) everywhere in my program. Obviously, I'm not going to do this.
There is no documentation from the author other than the API documentation, so I'm kind of at a loss as to why it was implemented this way instead of taking full advantage of the complete classes. One thing that bothers me is that I can't get the authors of an item when using the GenericSyndicationItem
type.
What can I do here? Make a wrapper class? Or inherit from the RssFeed
and AtomFeed
classes and implement an interface to expose the properties I feel should be similar from both?
When you are using a third-party library and the library doesn't meet your architectural needs: adapt! But how?
You've already identified some of your options and there are more:
If the existing classes really have no common base class at all, then the first two options are both about the same amount of work. Wrapping has the advantage of a little looser coupling in case you ever decide to switch to a different framework. Extending avoids a lot of code like
adaptee.AdapteeMethod
since you can call base methods without specifying an instance. In this case I would lean towards the adapter pattern unless there is at least some common base class you can exploit through inheritance.The last serious option is refactoring the code to be more object-oriented and I only recommend this approach if you are intending to contribute back to the project and have the blessing of the project's author. The reason is that you have working code that you probably don't full understand and messing around with it just risks breaking it. Leave the working code alone and adapt it from the outside.