Re: Design
- From: "Nick Malik [Microsoft]" <nickmalik@xxxxxxxxxxxxxxxxxx>
- Date: Fri, 30 Jun 2006 01:08:15 -0700
I'll just add to what Frans has already said. I agree with everything he
said, so start there.
<mojtaba_danai@xxxxxxxxx> wrote in message
news:1151637988.490203.304530@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
I am trying to make a adapter program.
-There can be different kind of adapters, which each can take data from
one source.
-It should be possible to plugin the new adapter for a new source of
data.
-The adapters all make a common structure to give it to the connected
clients. (I have implemented this part).
OK. so how are you adapting the data? You say common structure. Do you
mean common interface as well? I'm guessing here. Let's say that data
source 1 connects to MySQL to a pair of tables that implements name-value
pairs where the values are all string types. data source 2 connects to a
SQL Server database with a single table. You can return column names and
the values.
There are two interfaces here. One is for the API. OpenDB, GetData,
CloseDB. The other is for the data type: do you return an arraylist of
name-value pairs or a single predefined class for a record or an array of
name-value pairs or some other construct. In other words, seperate from the
API for getting the data, you have coupling on the structure of the data.
To do an adapter correctly, you have to decide what you want to adapt! In
other words, what can you consider constant and what will vary? You rarely
get the luxury of having both the API and the data structure to be static,
but I've seen it happen (usually with configuration information or
localization strings). More frequently, you are providing a single API for
accessing generic data, or you are providing some mechanism for converting
any inbound data into a single data format for consumption.
Which of these two are you needing?
-Each adapter uses a specific API to collect data from data source.
See Frans' answer. They can use a specific API but will the PRESENT a
single consistent API?
How the design of the adapter class should look like? Which design
pattern?
um... the Adapter pattern... is this a trick question?
http://home.earthlink.net/~huston2/dp/adapter.html
There should probably be a superclass for all adapters, right? But they
use different APIs, as I said before, and one of the adapters inherits
already from couple of data source API classes.
um... nope. Adapters inherit from the adapter class. They succeed by
providing a way to shield the calling code from the API being called, thus
allowing more than one API to be called by the same code through the
indirection of the adapter pattern.
I have no idea if my answers helped you.
--
--- Nick Malik [Microsoft]
MCSD, CFPS, Certified Scrummaster
http://blogs.msdn.com/nickmalik
Disclaimer: Opinions expressed in this forum are my own, and not
representative of my employer.
I do not answer questions on behalf of my employer. I'm just a
programmer helping programmers.
--
.
- References:
- Design
- From: mojtaba_danai@xxxxxxxxx
- Design
- Prev by Date: Re: Object identity
- Next by Date: Re: Object identity
- Previous by thread: Design
- Next by thread: Re: Designing issue
- Index(es):
Relevant Pages
|