2

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?

Dan Lowe
  • 51,713
  • 20
  • 123
  • 112
Pete
  • 10,651
  • 9
  • 52
  • 74

2 Answers2

3

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:

  1. Wrap existing classes in new classes using the Adapter Pattern
  2. Extend and unify disparate classes by implementing a common interface
  3. Refactor the original code to use Polymorphism natively

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.

Rick Sladkey
  • 33,988
  • 6
  • 71
  • 95
2

It has been a really long time since I wrote Argotic (it was written before System.ServiceModel.Syndication existed in .NET), but since the concept of author exists in both RSS 2.0 and Atom, I don't really recall why the generic feed item did not include an Authors collection. It may have been because the outline elements in an OPML document do not have the concept of author. Poor design on my part obviously.

The bottom line is I was still young and learning, and Argotic while useful when it was written 3 years ago; is woefully in need of a major refactoring. If System.ServiceModel.Syndication can fulfill your needs, I recommend you use that to parse your syndication feeds.

Since you have the full source code to Argotic, and it is not fulfilling your needs; you could add an Authors collection to the generic syndication item class and populate it when consuming an RSS or Atom feed.

You most definitely have my blessing to refactor as you see fit regardless of whether you contribute back, I passed off project responsibilities years ago and am not sure what state it is in these days.

That said and done, if you know the format of the feed prior to consuming it, you can do the following:

RssFeed feed = RssFeed.Create(new Uri("http://www.pwop.com/feed.aspx?show=dotnetrocks&filetype=master"));

AtomFeed feed = AtomFeed.Create(new Uri("http://news.google.com/?output=atom"));
Oppositional
  • 11,141
  • 6
  • 50
  • 63
  • Thanks for replying. Argotic is fine, I think I can make it work and it will still be the path of least resistance. I'm young and learning too (using Argotic for a group term project) so we'll see. System.ServiceModel.Syndication sucks for reading feeds as it fails too easily right out of the box. It's probably better for writing/creating well formed feeds. – Pete Jun 07 '11 at 13:01