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

Design and Architecture

 
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 
GeneralRe: Object Oriented Data Marshalling Pin
Adam Jasper8-May-08 22:11
Adam Jasper8-May-08 22:11 
Hi Leslie,

Thanks for your comments, much appreciated. I don't actually need to use a switch statement in this case. I try and avoid it where possible. Really the only time I use a switch statement is in a factory class, I can't think of a way around it in some instances.

I'll explain how I have avoided a case statement with code snippets (this is off the top of my head as I don't have the actual code to hand at the moment):

private Dictionary<BusinessEntityType, IEntityWorkflow> _workflows;<br />
<br />
public PersistenceWorkflow()<br />
{<br />
   _workflows = new Dictionary<BusinessEntityType, IEntityWorkflow>();<br />
<br />
   InitialiseEntityWorkflows();<br />
}<br />
<br />
protected virtual void InitialiseEntityWorkflows()<br />
{<br />
   _workflows.Add(BusinessEntityType.Tariff, new TariffWorkflow());<br />
   _workflows.Add(BusinessEntityType.Contract, new ContractWorkflow());<br />
}<br />
<br />


then, the actual save method is something like this:

public SimpleBusinessEntity Save(SimpleBusinessEntity entity)<br />
{<br />
   IEntityWorkflow workflow = _workflows[entity.EntityType];<br />
   return workflow.Save(entity);<br />
}


The implementation of the IEntityWorkflow.Save method in TariffWorkflow would cast to the relevant type e.g. TariffEntity.

I know the one disadvantage of this design is that I am instantiating more objects than I am going to use, however, I think it is a small price to pay for a very extensible design and I will never have that many entity workflows.

Regards,
Adam
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 
GeneralRe: Documentation Template Pin
led mike22-Apr-08 5:45
led mike22-Apr-08 5:45 

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.