Coffeehouse Thread

15 posts

Forum Read Only

This forum has been made read only by the site admins. No new threads or comments can be added.

Need Suggestions on Design pattern

Back to Forum: Coffeehouse
  • User profile image
    pwzeus

    I have always got good help from this forum so here I am back with a question.

    I am developing an image processing app. Which DESIGN PATTERN I should use. I am really confused and need some help.

    Here are the details.

    Dropdownlist with Image name and ID

    on selecting image id it will go to the database and grab the image.

    I want to make gineric objects which can deside what kind of image request is coming in from UI and then grab from database. I do have standerd UI / Business / Data layer in place.

    Thanks in advance

  • User profile image
    blowdart



    Well that lends itself to MVC

  • User profile image
    Rossj

    pwzeus wrote:
    


    I want to make gineric objects which can deside what kind of image request is coming in from UI and then grab from database. I do have standerd UI / Business / Data layer in place.



    Factory? Quiite hard to tell from your description, are you suggesting you want a single interface that will have concrete implementations that perform slightly different functionality (say diff image formats)? And a class that knows how to create specific instances of that interface?

    Or a facade if you have lots of different services (possibly web services) which currently don't have a common, but vaguely similar API.

  • User profile image
    pwzeus

    can you tell me more wtt u have in mind. Pardon my newbeness lol

  • User profile image
    blowdart

    pwzeus wrote:
    can you tell me more wtt u have in mind. Pardon my newbeness lol


    Well you're not giving us much to go on Smiley

    View renders the data from the Model in response to the request made to the model by controlled events made by user interaction.

    Model View Controller is a design approach to separate the application object model from GUI, originally invented around 80s. Then later on it has become a widely accepted common design pattern. The main objective behind this pattern is to decouple the view of the data (presentation layer) from the actual data processing so that the same model can be used for various views. This is achieved by using three different types of objects that interact with each other in loosely coupled manner with their discreet set of tasks.

  • User profile image
    pwzeus

    ok i will try to give more detail.

    (1) I have database with number of images

    (2) UI dropdownlist lists all those image name pulling from DB

    (3) When user selects and image name from DROP DOWN then I want my object to deside what to do form there. So This way my UI does not knowanything about what is going to happen.

    (4) Once I have iamge id in my object (business layer) it should have a logic which can determine the type of image based on image id ( i have some logic for this)

    (5) then that object needs to call approprite function from data layer and display that processed image on UI.

    today I have jpeg but tom. I can have gif,png or different kind of iamges so for that I would like to make all these objects generic. So I woult lvoe to see which design pattern will make my life easier.

    Thanks for your support

  • User profile image
    blowdart

    OK factory patten for the generic object stuff.
    MVC for the UI.

  • User profile image
    pwzeus

    ok I can understand MVC here but i m not sure how factory pattern will be usefull. I will look into it....thanks

  • User profile image
    JohnAskew

    Factory fetches/creates the image(s) for the request(s), no?

    It is the controller-to-DAL link, I would guess.


    BTW, Model/View/Controller is quickly being dropped for Model/View/Presenter; (MVC => MVP).

    The Presenter handles all traffic between UI and BOL, a Controller doesn't handle BOL -> UI, is the difference. MVP came about to best support TDD, from what I've read.

    There is a good architectural video series here on C9 that describes the "Presenter First" design pattern. We start in the middle with the Presenter and write to Interfaces forward and backward -- for UI and BOL. This gives a tight design, tight like a tiger.

    Factory is not foundry, it can be a simple static class that cuts farts.

  • User profile image
    blowdart

    JohnAskew wrote:
    simple static class that cuts farts.


    Errr ..... was that a mistype?

  • User profile image
    JohnAskew

    blowdart wrote:
    
    JohnAskew wrote:
    simple static class that cuts farts.


    Errr ..... was that a mistype?


    Actually, my wife calls me a static fart factory most evenings after bean soup and beers.

  • User profile image
    pwzeus

    that looks more work then the problem itself......i understand design patterns are good but overuse is also not good. All i need is to send image id via business alyer and datalayer and get the data back. MVP will not fit in this scenario as we are not doing no TDD or changin UIs often. Plus I dont see how i can fit factory pattern for this solution. Sorry if i m missing something but from where i m looking i see not water in the desert...Perplexed i need to go home

  • User profile image
    Rossj

    pwzeus wrote:
    ok I can understand MVC here but i m not sure how factory pattern will be usefull. I will look into it....thanks


    Think static method that returns a concrete implementation of an interface based on some criteria, sample pseudo here from top of my head ..

    interface IImageHandler{ ... }

    sealed class ImageHandlerFactory
    {
        private ImageHandlerFactory {}

        public static IImageHandler Create( object criteria )
        {
               IImageHandler handler = null;
               switch( criteria )
               {
                     case X:
                       handler = new PngImageHandler();
                       break;
                     case Y:
                        handler = new GifImageHandler();
                         break;
                }
               return handler;
        }
    }

    Of course you could make it a lot more flexible by having the criteria match against configuration, dynamically load the implementation (and cache it).

  • User profile image
    Rossj

    Dupe.

  • User profile image
    JohnAskew

    Factory pattern is a static class that asks the DAL for data and formats it for the UI to consume. A picture factory; not bricks and mortar, factories can be tiny, it's just a pattern, not a huge construct.

Conversation locked

This conversation has been locked by the site admins. No new comments can be made.