Mombu the Programming Forum sponsored links

Go Back   Mombu the Programming Forum > Programming > C++ design question
User Name
Password
REGISTER NOW! Mark Forums Read

sponsored links


Reply
 
1 26th March 04:33
jlin008
External User
 
Posts: 1
Default C++ design question



Hi,

I have a design question. I am making a time series ****ysis tool.
Since I already use STL vector to represent time series, is there a
need to implement a class for the time series object? Right now I
just use

typedef vector<double>TS;

Is that enough? I feel that I am not taking advantage of the C++
encapsulation. But implementing the class seems redundant.. I'd
appreciate some insight! Thanks in advance!

Jessica
  Reply With Quote


  sponsored links


2 31st March 05:31
cy edmunds
External User
 
Posts: 1
Default C++ design question



I wouldn't say that "taking advantage of the C++ encapsulation" is an issue.
But as you develop your project it seems likely you will find more to say
about a time series than just the time values themselves. If so you will
wish you had started with a class like this:

class TimeSeries
{
public: typedef double t_time;
typedef std::vector<double> t_series;
private:
t_series m_series;
// probably other stuff to be added here later public: TimeSeries() {}
template <typename ITER> TimeSeries(ITER first, ITER last) :
m_series(first, last) {}
const t_series &series() const {return m_series;}
t_series &series() {return m_series;}
// accessors for new stuff to be added here as needed
};

[untested code] As you can see, there isn't that much to it and if you
decide to add some other properties to TimeSeries you can do so without
breaking your code. If you diligently declare times as TimeSeries::t_time
and container references as TimeSeries::t_series you can change your mind
about those types later. You will have to use syntax such as:

TimeSeries::t_time t = my_ts.series().front();

rather than

TimeSeries::t_time t = my_ts.front();

Not so terrible, IMHO.

--
Cy Edmunds
http://home.rochester.rr.com/cyhome/
  Reply With Quote
3 31st March 05:31
phlip
External User
 
Posts: 1
Default C++ design question


Forget encapsulation.

(On modern projects, a given binary only grows so large before we use a pipe
or COM to plug it into a bigger app, so that's the encapsulation boundary.)

Focus on removing duplication.

If two clients do similar things to a vector of doubles, refactor them until
their code looks similar.

Then, replace the two similar procedures with a call to a new function,
containing those common lines.

The simplest place to put that common function is inside a class that also
contains TS.

Voila: Objects.

--
Phlip
http://www.c2.com/cgi/wiki?TestFirstUserInterfaces
  Reply With Quote
Reply


Thread Tools
Display Modes




Copyright © 2006 SmartyDevil.com - Dies Mies Jeschet Boenedoesef Douvema Enitemaus -
666