Design Pattern for Filters

9

First, filter in my current context is a list of objects to be used in ComboBox type controls so that the user can choose from the options.

My scenery: Screen 1 - It has filters of companies, stocks, customers, forms of payment. Screen 2 - It has filters of companies and stocks. Screen 3 - It has filters for customers, cities, states.

My goal is to implement a design pattern that uses the same structure, eg FilterStream, and add the filters (companies, clients, stocks) depending on the screen that requested it.

These screens are from a windows forms project, the request will be made to a WCF Service, which will query in a database and return the structure with all filters to the client (windows forms).

Something around, WCF Service I "Screen 1" want the filters companies, stocks, customers and forms of payment, upon receiving the msg back, would make the respective binding for each control.

Can someone tell me a design pattern to solve this question?

    
asked by anonymous 04.08.2015 / 18:52

3 answers

3

You can combine @RogerOliveira's response on the SQL side with the Builder and Fluent Interfaces on the C # .

Basically you would use the filter like this:

new FiltroTelaBuilder().porEmpresa(empresa).build();

Or so:

new FiltroTelaBuilder().porCliente(cliente).build();

Or so:

new FiltroTelaBuilder().porEmpresa(empresa).porCliente(cliente).build();

In all cases the build() method returns an immutable instance of FiltroTela .

There are different ways to implement this pattern. This is the most common.

    
19.11.2015 / 05:49
3
  

Answer originally posted in the body of the question by its own author

Well, I found a pattern that helped me and a lot, the Decorator, follows a reference link "# and below is a short example of how the implementation of the assembly of the filters came in, which caters to my screen:

private Dictionary<string, object> FiltroTela1()
    {
        IFilter filtro = new Filter();
        filtro = new FilterCompany(filtro);
        filtro = new FilterCustomer(filtro);
        filtro = new FilterPaymentType(filtro);
        return filtro.Filters();
    }

private Dictionary<string, object> FiltroTela2()
    {
        IFilter filtro = new Filter();
        filtro = new FilterCustomer(filtro);
        filtro = new FilterPaymentType(filtro);
        return filtro.Filters();
    }

The two examples above use Decorator to "decorate" my Filter object with the necessary filters for each screen, and the "Filters" method obtains from each filter the type and an object to be used as criteria in the filter search.

On the other end "Server", I use the same standard, it analyzes the received dictionary and gets the requested filters from the database, assembles a new filter, but with the list of each one and returns to the screen, which by it analyzes the received filters and performs the binding for the respective control.

    
19.11.2015 / 13:49
1

I pass the filters as parameters in the Stored Procedure using this sql:

@parametro is null or campo = @parametro

As soon as you pass null in the parameter it will ignore, hence simply pass on parameters to SP if null your treat before.

    
14.09.2015 / 01:38