views:

90

answers:

3

What I have?

I have below requirements:

  • Search the database and return TreeNode objects to build a tree view
  • Search the database and return a generic list to construct a diagram.
  • Extensibility should be there to do search and return different type of objects
  • Database is huge and performance should be considered with high priority

What problem am I facing?

I am trying to do a class design for the problem. Here, searching method is same and only return type differs. I am confused which design pattern to use here.

Can somebody help me in this?

Thanks in advance!

Update-1

Searching logic will be same and APIs are provided that purpose. The APIs will accept search parameters and return the results as a DataReader (in C#). Using the reader, I need to construct either TreeNode, a generic list, or any other object that may come in future.

I need to design a component that sits in business layer to serve the presentation layer. Depending on the user's selection, the search results will be displayed with different controls. These controls need different type of objects to bind.

A: 

Well, you named general functionality you'd like to implement. However you didn't mentioned consumers of this functionality. And usage scenarios is the driving force behind design. So in order to proceed with design you need to specify scenarios. For example, there is no point in abstracting searching algorithms behind Strategy pattern unless it will be used polymorphycally.

Dzmitry Huba
I have updated the question. Thanks for your time!
Vijay
+1  A: 

I truly don't understand the problem. Your list of requirements is too vague.

What is your database ? How do you access it ? What kind of data is in there ? What kind of program are you designing ? On which sub-part of the design do you have problems ?


Update

Okay, so i think you have to set up 2 patterns.

First of all, you will need a way to retrieve the data from the database in a unified format. This should be done using an [abstract] Factory pattern. The Factory would just provide a standard container (your Reader) for fetched data.

Next, you will need something to adapt this unified data (namely, an Adapter). This would just be a set of functor-like structures that would be able to transform from the standard unified fetched data (from the database), to the component-specific required data.

The factory should stay in the business layer, whereas the adapters should be in the presentation layer.

Aurélien Vallée
I have updated the question.Thanks for your time.
Vijay
Okay. Let me try that out. Thanks!
Vijay
A: 

I think you'll need to look at the Factory pattern.

The interface will request a tree or list or X Creator from the factory, and the creator will then perform the search and interpret the DataReader to construct the datatype of choice.

NomeN