tags:

views:

35

answers:

1

Hello,

I'd like to ask your opinion whether it's good to use Bridge pattern in scenario or not. The scenario is that we need to develop one generic search UI that can accept the different search parameters and based on those parameters, we need to call the different services. For example: If the parameters is FIN number and Name of Person then we will have to call PersonService to search.

In order to make type-safe, I'm thinking to use the Bridge patter where the abstraction and implementation can work independently.

After implementing the code below, I feel like I'm forcing myself to use that pattern in this scenario even that pattern is not well suite for this...

What do you guys think? Is there any way to change the code to make it better? or this pattern can't be used for this scenario at all?

abstract class SearchEngine { public abstract IList Query(); }

class PersonSearchEngine : SearchEngine<Person> {

    private DataQuery<Person> dataQuery;

    public PersonSearchEngine(DataQuery<Person> dataQuery){
        this.dataQuery = dataQuery;
    }

    public string FIN { set; get; }
    public string Name { set; get; }

    public override IList<Person> Query() {
        return dataQuery.Query(new Person() { FIN = this.FIN, Name = this.Name });
    }

}

class LocationSearchEngine : SearchEngine<House> {

    private DataQuery<House> dataQuery;

    public LocationSearchEngine(DataQuery<House> dataQuery) {
        this.dataQuery = dataQuery;
    }

    public string BlockNumber { set; get; }
    public string StreetName { set; get; }
    public string HouseNumber { set; get; }
    public string PostalCode { set; get; }

    public override IList<House> Query() {
        return dataQuery.Query(new House() { BlockNumber = this.BlockNumber, StreetName = this.StreetName, HouseNumber = this.HouseNumber, PostalCode = this.PostalCode});
    }
}




abstract class DataQuery<T>{
    public abstract IList<T> Query(T arg) ;
}

class PersonDataQuery : DataQuery<Person> {

    public override IList<Person> Query(Person arg) {
        Console.WriteLine("Searching Person.....");
        return null;
    }
}

class LocationDataQuery : DataQuery<House> {        

    public override IList<House> Query(House arg) {
        Console.WriteLine("Searching Location.....");
        return null;
    }
}

class Person {
    public string FIN { get; set; }
    public string Name { get; set; }
}

class House {
    public string BlockNumber { set; get; }
    public string StreetName { set; get; }
    public string HouseNumber { set; get; }
    public string PostalCode { set; get; }
}

Usage:

        SearchEngine<Person> searchEngine = new PersonSearchEngine(new PersonDataQuery());            
        searchEngine.Query();


        Console.ReadKey();
A: 

If the search will always be routed to a single subsystem. How about a routing pattern.

If the search result will be aggregated for several subsystems. How about an aggregator pattern.

Shiraz Bhaiji