oop - dlang inheritance design for types passed between threads -


i'm writing multithreaded program in d programming language, pretty new language. there restriction on types passed between threads using tid.send() , receive[only]() apis in std.concurrency package must value types or must constant avoid race conditions between sender , receiver threads. have simple struct message type have been passing value:

enum messagetype {     preparerequest,     prepareresponse,     acceptrequest,     accepted }  struct message {     messagetype type;     systime timestamp;     uint node;     ulong value; } 

however, messagetypes don't have fields, , it's annoying use switch statement , remember types have fields when use polymorphism work automatically. using immutable class hierarchy recommended here, or approach i'm using best way go, , why?

edit

also, if should use immutable classes, what's recommended way create immutable objects of user-defined class? static method on class come casts return value immutable?

as rule of thumb, if have polymorphic type hierarchy, classes tool use. , if mutation out of question design, immutable classes should trick efficiently.

great presentation dconf2013 ali has been published : http://youtu.be/mpr2usps0fe . goes through topic of usage of const , immutable in d in great detail. among other stuff suggests use auto var = new immutable(classtype)(...); syntax creating immutable classes. initialization goes constructor , no special hacks needed.


Comments

Popular posts from this blog

php - cannot display multiple markers in google maps v3 from traceroute result -

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -