Click here to Skip to main content
15,887,585 members
Home / Discussions / Design and Architecture
   

Design and Architecture

 
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 
GeneralRe: Object Oriented Data Marshalling Pin
Adam Jasper11-May-08 23:39
Adam Jasper11-May-08 23:39 
GeneralNeed suggestion Pin
Cryptogrpahy29-Apr-08 1:41
Cryptogrpahy29-Apr-08 1:41 
GeneralRe: Need suggestion Pin
Member 9630-Apr-08 6:25
Member 9630-Apr-08 6:25 
GeneralRe: Need suggestion Pin
Cryptogrpahy30-Apr-08 6:37
Cryptogrpahy30-Apr-08 6:37 
GeneralRe: Need suggestion Pin
Member 9630-Apr-08 7:03
Member 9630-Apr-08 7:03 
GeneralRe: Need suggestion Pin
Mark Churchill1-May-08 17:20
Mark Churchill1-May-08 17:20 
GeneralNeed suggestions to define architecture Pin
pranabdas25-Apr-08 9:11
pranabdas25-Apr-08 9:11 
QuestionRequirements gathering tools Pin
Pawel Krakowiak24-Apr-08 4:49
Pawel Krakowiak24-Apr-08 4:49 
GeneralDesign pattern - Exporting results to different formats Pin
jonnyvargazz24-Apr-08 3:44
jonnyvargazz24-Apr-08 3:44 
GeneralRe: Design pattern - Exporting results to different formats Pin
PIEBALDconsult25-Apr-08 6:12
mvePIEBALDconsult25-Apr-08 6:12 
GeneralRe: Design pattern - Exporting results to different formats Pin
jonnyvargazz28-Apr-08 0:34
jonnyvargazz28-Apr-08 0:34 
GeneralRe: Design pattern - Exporting results to different formats Pin
Sameerkumar Namdeo2-May-08 22:21
Sameerkumar Namdeo2-May-08 22:21 
QuestionWhat is a properties file? Pin
pl_kode24-Apr-08 0:14
pl_kode24-Apr-08 0:14 
GeneralRe: What is a properties file? Pin
K.L.K29-Apr-08 15:10
K.L.K29-Apr-08 15:10 
General[Message Deleted] Pin
C. L. Phillip22-Apr-08 5:10
C. L. Phillip22-Apr-08 5:10 

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.