I am playing around with Object Oriented Design/Database design by creating an application that can pull info from various Sources like Amazon or IMDB to keep info on movies/music/books I have or have watched/read etc… Product objects such as Movie, Book, Album etc.. are composed of attributes from 1 or more sources, with some overlap between the different types of objects(eg all products would have a Title, ASIN to name a few). In addition, various Sources could have some of the same information(eg Release Date), and some different information(for instance IMDB contains more info on cast members that I may want to use, while I would not pull this info from Amazon). I would want to be able to choose which source I get these overlapping attributes from. See the linked image for a simple example:
http://imageshack.us/photo/my-images/194/drawing1r.png/
It seems like redefining all the attributes that I defined in the Parser classes in the Movie class is a bit redundant, and even moreso if I continue to create other classes such as Book, Album(redefining ASIN, IMDBId etc…). It just seems I am approaching this wrong.
Any suggestions for a better design that is easier to extend and maintain?
You could create a superclass called ‘
Product‘ that holds the common properties between your Movie, Book and Albums. Then each of these particular object types would inherit from the common parent class.Shouldn’t Amazon and IMDB parsers create the Product objects? Why do they hold properties of products? If you parse each product individually, you could say that each product parses itself, and include the code in each particular product class (or the parent). Each object should really have a certain function or represent a certain object – do your parsers represent an object or do they perform a function (parsing) which creates an object?
You could also create a common parent class for each type of Source, or an Interface (
IProductSource) and then call methods of that interface, without your particular objects knowing/caring about which actual data source is behind the interface.