Note that there are some explanatory texts on larger screens.

plurals
  1. POWhich C++ design approach is more maintainable?
    primarykey
    data
    text
    <p>The current specifications is: </p> <p>Given string data in the form of wide or narrow character arrays write the functionality for a class that provides statistics on the data and modifies the data.</p> <p>The requirement is for it to be maintainable over the long term.</p> <p>So my first approach is to require the raw char arrays be marshalled into strings prior, then just provide a template class:</p> <pre><code>template&lt;class T&gt; class MyString { private: T _data; public: MyString(T&amp; input) { _data = input; }; size_t doSomeWork() { //assume T is of type basic_string&lt;...&gt; and use iterators }; }; //Use const char* data = "zyx"; string blahblah(data); MyString&lt;string&gt; abc(blahblah); abc.doSomeWork(); </code></pre> <p>or static member functions:</p> <pre><code>class StringTools { public: static size_t doWork(const char*) {} static size_t doWork(const wchar_t*) {} }; //used like so: const char* data = "hallo kitty"; cout &lt;&lt; StringTools::doWork(data); </code></pre> <p>or use a strategy pattern:</p> <pre><code>class MyString { protected: MyStringBase(); public: virtual ~MyStringBase(); virtual size_t doWork() = 0; }; class MyStringCharArray : public MyString { protected: char* _data; public: MyStringCharArray(const char* input) : MyString() { } virtual size_t doWork() {...}; }; //so it would be used like so const char* blah = "blah"; MyString* str = new MyStringCharArray(blah); cout &lt;&lt; str-&gt;doWork(); delete str; </code></pre> <p>and then in the future if for some god forsaken reason i switch to BStr's then it would only require that the first two lines of code be changed in addition to a new derived class being written.</p> <p>I think that if i write a wrapper class as in 1 &amp; 3 it becomes alot more heavy duty and any encapsulation is broken as i'd have to allow access to the underlying.</p> <p>but if i create a class with only static functions then all it does is mimic a namespace which would be better served by some non-member non-friend functions encapsulated under a "stringtools" namespace. But then i'd still be propagating the messyness of raw character arrays throughout the application and extra validation would have to be performed etc and the specification asked explicitly for a class.</p> <p>So what would be the cleanest and most maintainable approach to take?</p> <p>rgds</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload