Click here to Skip to main content
15,922,427 members
Home / Discussions / Design and Architecture
   

Design and Architecture

 
AnswerRe: Instance vs Static + Option Pin
Member 9614-May-08 8:37
Member 9614-May-08 8:37 
GeneralRe: Instance vs Static + Option Pin
Brady Kelly14-May-08 10:23
Brady Kelly14-May-08 10:23 
AnswerRe: Instance vs Static + Option Pin
Ed.Poore15-May-08 21:35
Ed.Poore15-May-08 21:35 
AnswerRe: Instance vs Static + Option Pin
Megidolaon11-Jun-08 3:57
Megidolaon11-Jun-08 3:57 
QuestionFunction Extraction \ Refactoring Pin
Ray Cassick30-Apr-08 19:42
Ray Cassick30-Apr-08 19:42 
AnswerRe: Function Extraction \ Refactoring Pin
Zoltan Balazs30-Apr-08 20:15
Zoltan Balazs30-Apr-08 20:15 
GeneralRe: Function Extraction \ Refactoring Pin
Megidolaon11-Jun-08 4:01
Megidolaon11-Jun-08 4:01 
AnswerRe: Function Extraction \ Refactoring Pin
Big Daddy Farang1-May-08 12:19
Big Daddy Farang1-May-08 12:19 
AnswerRe: Function Extraction \ Refactoring Pin
Luc Pattyn1-May-08 12:54
sitebuilderLuc Pattyn1-May-08 12:54 
AnswerRe: Function Extraction \ Refactoring Pin
peterchen10-May-08 23:02
peterchen10-May-08 23:02 
GeneralObject Oriented Data Marshalling Pin
Adam Jasper29-Apr-08 3:37
Adam Jasper29-Apr-08 3:37 
GeneralRe: Object Oriented Data Marshalling Pin
R. Giskard Reventlov29-Apr-08 21:40
R. Giskard Reventlov29-Apr-08 21:40 
GeneralRe: Object Oriented Data Marshalling Pin
Adam Jasper29-Apr-08 22:34
Adam Jasper29-Apr-08 22:34 
GeneralRe: Object Oriented Data Marshalling Pin
led mike30-Apr-08 4:24
led mike30-Apr-08 4:24 
GeneralRe: Object Oriented Data Marshalling Pin
Adam Jasper30-Apr-08 4:32
Adam Jasper30-Apr-08 4:32 
GeneralRe: Object Oriented Data Marshalling Pin
led mike30-Apr-08 5:04
led mike30-Apr-08 5:04 
GeneralRe: Object Oriented Data Marshalling Pin
Adam Jasper30-Apr-08 5:38
Adam Jasper30-Apr-08 5:38 
GeneralRe: Object Oriented Data Marshalling Pin
led mike30-Apr-08 7:31
led mike30-Apr-08 7:31 
GeneralRe: Object Oriented Data Marshalling Pin
Adam Jasper30-Apr-08 23:01
Adam Jasper30-Apr-08 23:01 
GeneralRe: Object Oriented Data Marshalling Pin
R. Giskard Reventlov30-Apr-08 4:32
R. Giskard Reventlov30-Apr-08 4:32 
GeneralRe: Object Oriented Data Marshalling Pin
led mike30-Apr-08 4:52
led mike30-Apr-08 4:52 
GeneralRe: Object Oriented Data Marshalling Pin
R. Giskard Reventlov30-Apr-08 21:16
R. Giskard Reventlov30-Apr-08 21:16 
GeneralRe: Object Oriented Data Marshalling Pin
Leslie Sanford8-May-08 18:23
Leslie Sanford8-May-08 18:23 
You have something like this?

public SimpleBusinessEntity Save(SimpleBusinessEntity entity)
{
    switch(entity.EntityType)
    {
    case EntityType.TariffEntity:
        tariffWorkflow.Save((TariffEntity)entity);
        break;

    case EntityType.Contract:
        contractWorkflow.Save((Contract)entity);
        break;

    default:
        Debug.Fail();
        break;
    }
}


Is this more or less correct?

In an object oriented approach, you use polymorphism to do the dispatching. This means creating several Save methods, one for each type:

public void Save(TariffEntity entity)
{
}

public void Save(ContractEntity entity)
{
}


The general consensous is that it's easier to maintain the latter approach than the long switch statements. This is especially true if you have several switch statements duplicate switch statements throughout your code.

Having said this, there are times where switch statements are appropriate. At the boundary of an application (which may apply here) you may find yourself having to switch on data in order to transform it into a form the rest of the application can use. For one thing, C# doesn't support double dispatching, so having several Save methods like the above may not work.

At any rate, hope something in the above provides some insight.
GeneralRe: Object Oriented Data Marshalling Pin
Adam Jasper8-May-08 22:11
Adam Jasper8-May-08 22:11 
GeneralRe: Object Oriented Data Marshalling Pin
Leslie Sanford9-May-08 6:31
Leslie Sanford9-May-08 6:31 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.