'. '

Talk:Trait

From APIDesign

(Difference between revisions)
Jump to: navigation, search
(Comment provided by Miles Elam - via ArticleComments extension)
Line 12: Line 12:
--Miles Elam 20:26, 4 September 2012 (CEST)
--Miles Elam 20:26, 4 September 2012 (CEST)
</div>
</div>
 +
 +
I am primarily interested in properly typing the multiple class encapsulation case. E.g. having prev/next field in the item class and manipulating them in only by the list. Moreover I'd like to write this (and type this) in a generic way. Looks like it will be possible to do it in [[C++]], but the solution will definitely not be like in [[Java]]/[[Scala]] - rather ''upside-down''...
 +
 +
--[[User:JaroslavTulach|JaroslavTulach]] 22:25, 5 September 2012 (UTC)

Revision as of 22:25, 5 September 2012

Comments on Trait <comments />


Miles Elam said ...

Yes, this is indeed possible in C++ and is, in fact, used extensively in the C++ standard library (aka STL). For a prime example, look no further than std::string or the various pluggable memory allocators. The example given in the article appears to these eyes as one of a C programmer trying to make C++ do things like C and failing. To be more precise, if one is accessing people objects by iterator, why would a raw pointer to a person need to be manipulated in this way? In addition, what happens if the object must be accessed in multiple ways, e.g., exists in both a normal list and a sorted list (or multiple sorted lists). The C method falls down as there is no single pair of *next and *prev but rather multiple.

Don't get me wrong, C definitely has its uses. Its relative simplicity for one. However, C++'s generic algorithms and data structures should not be discarded so lightly.

--Miles Elam 20:26, 4 September 2012 (CEST)

I am primarily interested in properly typing the multiple class encapsulation case. E.g. having prev/next field in the item class and manipulating them in only by the list. Moreover I'd like to write this (and type this) in a generic way. Looks like it will be possible to do it in C++, but the solution will definitely not be like in Java/Scala - rather upside-down...

--JaroslavTulach 22:25, 5 September 2012 (UTC)

Personal tools
buy