Click here to Skip to main content
6,306,412 members and growing! (17,175 online)
Email Password   helpLost your password?
Development Lifecycle » Design and Architecture » General     Intermediate License: The Code Project Open License (CPOL)

Abstract Factory Design Pattern for SearchFactory - Practical Approach

By Pratik.Patel

This article explains the practical approach to employ abstract factory design pattern using an example of searching module in Document Review System
Windows, Visual Studio, Dev
Posted:1 Nov 2006
Views:10,481
Bookmarked:6 times
Unedited contribution
Announcements
Loading...
 
Search    
Advanced Search
printPrint   Broken Article?Report       add Share
  Discuss Discuss   Recommend Article Email
9 votes for this article.
Popularity: 2.34 Rating: 2.45 out of 5
2 votes, 22.2%
1
2 votes, 22.2%
2
2 votes, 22.2%
3

4
3 votes, 33.3%
5

Introduction

Abstraction concretes almost everything!! The idea here is to promote the power of abstract factory design patterns in one of my latest project of document management system. My project deals with the content searching for documents and returning the results that is displayed in the grid (typical methodology of showing search results, isn�t it? ). This code article deals with the architecture of the searching module which I have implemented to solve typical problems and to make architecture more candid and tangible. This article might be helpful for those who are developing similar kind of application and are looking for similar abstractions. Please note that this article deals with design concepts so the body of methods in code has been kept empty. You can insert your own code to make it work!!

Background

There are quite a few articles of abstract factory design available on internet. Most of them include bookish examples like draw, run, move, play, etc� not for developers who demand cutting edge solutions (no offence meant). �Abstract factory design pattern deals with the way the objects are created. There is one abstract class which defines the factory method to create the object of its child class based on the parameters passed�

Using the code

The code structure is very simple. There are four classes viz. SearchFactory, ProximitySearch, SimilaritySearch, SimpleSearch. There are three types of searches in my module viz. Proximity, Similarity and Simple. Detail description on how these searches perform is out of the scope of this article (I will post it separately) The code here defines SearchFactory class as an abstract class which has the factory method called GetSearchObject(). This method is also called parameterized factory method which takes parameter for the type of object that is to be created. All the three searches has one class each, defined in the code. All these classes (ProximitySearch, SimilaritySearch, SimpleSearch) inherit the SearchFactory class to provide concrete implementation. Apart from factory method, SearchFactory (the base class of all searches) defines several other abstract functions which are common for all these three types of searches (simple search, proximity search and similarity search). Idea is to make all of them abstract in SearchFactory and let each search override each of those abstract functions. Those abstract functions are as follows:-
        public abstract void GetSearchResult(); 

        public abstract void ExecuteSearch();

        public abstract void SaveAndSearch();

        public abstract void ValidateSearch();
        
        public abstract void UpdateDisplayName();
You can refer code for this. The typical search factory method is given as follows. Based on the parameter searchType the object will be created for ProximitySearch, SimpleSearch and SimilaritySearch.
public static SearchFactory GetSearchObject(string searchType)
    {
        SearchFactory objContentSearchObject = null;
        if(searchType.ToString().ToUpper() == "SIMPLE")
        {
            objContentSearchObject = new SimpleSearch();    
        }

        if(searchType.ToString().ToUpper() == "PROXIMITY")
        {
            objContentSearchObject = new ProximitySearch();    
        }

        if(searchType.ToString().ToUpper() == "SIMILARITY")
        {
            objContentSearchObject = new SimilaritySearch();    
        }

        return objContentSearchObject;
    }    

Conclusion

This article targets to the developers who are starving to get practical usage of design patterns. This article is at the draft level and might contain few errors or bugs and thereby I welcome suggestion or criticism!! Developers who would like to challenge my code can write their comments on this code without any hesitation. Starving for perfection 

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Pratik.Patel


Member
He is a Computer science graduate with the total work experience of around 4 years on microsoft technologies primarily on C#.NET. Currently working on C++/COM+ with active directory (He loves playing with AD). He also has experience on MS-CRM and ASP.NET and holds MCP certification for 70-316.

Along with Software Development, he likes to play harmonica (Mouthorgan) and spend the weekend researching on new coding techniques published on www.codeproject.com

People say dont re-invent the wheel, I say I've got a better wheel!
Occupation: Software Developer (Senior)
Company: Symphony Services Corp. India Pvt. Ltd.
Location: India India

Other popular Design and Architecture articles:

Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 4 of 4 (Total in Forum: 4) (Refresh)FirstPrevNext
GeneralGetSearchObject PinmemberPete O'Hanlon2:55 2 Feb '07  
GeneralFactory Method PinmemberMikeonn2:04 2 Feb '07  
Generalnice one PinmemberAshish Basran4:18 3 Nov '06  
GeneralRe: nice one PinmemberPratik.Patel20:32 5 Nov '06  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 1 Nov 2006
Editor:
Copyright 2006 by Pratik.Patel
Everything else Copyright © CodeProject, 1999-2009
Web18 | Advertise on the Code Project