Design patterns..

F

farseer

i'm looking for the right solution to my problem.

i have an app that uses certain core set of data object that it knows
about and operates on. The source of the actually data however may
come from various sources, including webservices, that return that data
in their own objects. So to keep my application operating on the
objects it only knows, i need to transform the incoming data objects
into my app's data objects. important: The incoming data objects do
not support a common interface.

I thought an Adapter or Bridge pattern would be ideal here, but i
realize that for ever new datasource, i may have to add more and more
adapters..is that good design? are there better alternatives?
 
P

Pete Davis

The adapter pattern is generally the way I would do it.

That said, I sometimes find that having some sort of generic adapter that's
extensible without having to build new plugins or rebuild the main app is
helpful.

What I generally will do is try to come up with some sort of system (and
it's hard to describe any specifics without know the types of data sources
you're talking about), that allows me to easily extend it.

To give you an example, I have an app that pulls images off of certain web
pages. Now, I could write different code for each web page to extract the
data, but that would be cumbersome and a pain to extend.

Instead, what I've done is created an xml config file that I place the URL
of the page and a regular expression that's used to extract the images. Then
all I have to do is come up with the regular expression that extracts the
information I'm interested in and add that and the URL to my config file.
Much easier than custom coding an interpreter for each page.

But there may be cases where a regular expression may not be able to bend
the original page to what I want it to do. In that case, I have a plugin
architecture as well that allows me to write a plugin for the app that will
then do a custom interpretation for that particular site.

This keeps me from having to modify the main application every time.

Anyway, those are some ideas.

Pete
 
F

farseer

thanks for the feedback. i have decided the adapter pattern is best
here...i am using something similar to a datasource adapter tht would
allow the app to fetch data from any datasource, wether it be a
database, webservice, or filesystem. it seems to fit very well with
what i hope to achieve
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top