4

I have an object that takes in data and spits out a transformed output, called IBaseItem.

I also have two parsers, IParserA and IParserB. These parsers transform external data (in format dataA and dataB respectively) to a format usable by my IBaseItem (baseData).

I want to create 2 systems, one that works with dataA and one that works with dataB. They will allow the user to enter data and match it to the right plugins/implementations and transform the data to outData.

I want to write these traffic cops myself, but have other people provide the parsers and baseitem logic, and and as such am implementing these items as plugins (hence the use of interfaces). Other programmers can choose to implement 1 or both parsers.

Q: How should I structure the way base items and parsers are associated, stored, and loaded into each of my programs?

Class Relations: enter image description here

What I've Tried:

Initially I though there should be a different dll for each of my 2 traffic cops, that each have a parser and baseitem in them. However, the duplication of baseitem logic doesn't seem right (especially if the base item logic changes).

I then thought the base items could all have their own dll, and then somehow associate parsers and baseitems (guids?), but I don't know if implementing the overhead id/association is adding too much complexion.

1 Answer 1

2

I'd structure this solution like this:

  • You would have a single assembly which contains the IBaseItem contract (and any other contracts you expose to your consumers). Call this a contract assembly.
  • You may then need a second assembly which contains any shared code for your two parsers. Depending on the nature of your solution this shared code could go in the contract assembly, or may need to go into a base parser logic assembly. This base parser assembly would almost certainly need to reference the contract assembly to perform basic functions.
  • Finally, the two parsers can exist in their own projects and reference both of the other assemblies.

I don't follow with the mention of associating parsers with baseitems through guids. The question only mentions one baseitem, and each parser only knows one data type - it's a simple enough process to parse your one known input type into your one known output type.

1
  • I would agree, this is a common way of designing a system like this
    – Xharze
    Jul 5, 2012 at 7:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.