Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > interface principle

Reply
Thread Tools

interface principle

 
 
bluekite2000@gmail.com
Guest
Posts: n/a
 
      08-12-2005
I have
//vector_header.h
template <typename T>
class Vector
{
....
}

//vector_func.h
#include vector_header.h
template<typename T>
Vector<T> sqrt(Vector<T>& Vin);
#include "vector_func.cc"

//vector_func.cc
template<typename T>
Vector<T> sqrt(Vector<T>& Vin)
{
....
}

My question is: Is sqrt() logically a part of class Vector? If it s
not, should I make it so? How do I go about making it a part of class
Vector? I d rather not put it in the same header file. Can I put it in
the same namespace instead?

 
Reply With Quote
 
 
 
 
Victor Bazarov
Guest
Posts: n/a
 
      08-12-2005
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> I have
> //vector_header.h
> template <typename T>
> class Vector
> {
> ...
> }
>
> //vector_func.h
> #include vector_header.h
> template<typename T>
> Vector<T> sqrt(Vector<T>& Vin);


I thought it should be

... sqrt(Vector<T> const & Vin);

(notice the 'const')

> #include "vector_func.cc"
>
> //vector_func.cc
> template<typename T>
> Vector<T> sqrt(Vector<T>& Vin)
> {
> ...
> }
>
> My question is: Is sqrt() logically a part of class Vector?


No.

> If it s
> not, should I make it so?


Depends. If you accept my 'const' suggestion, then any other object
that can be converted to 'Vector<??>' will be accepted as the argument
of 'sqrt'. If you make it a member, then such conversion will not be
applicable.

> How do I go about making it a part of class
> Vector?


Uh... How do you make it a part? You mean, a member, right? What
else is "a part"?

> I d rather not put it in the same header file. Can I put it in
> the same namespace instead?


I don't understand this question. If it's a member, then it's gotta
go in the same header. If it's not a member, you can put it anywhere
you like.

V
 
Reply With Quote
 
 
 
 
bluekite2000@gmail.com
Guest
Posts: n/a
 
      08-12-2005
No I dont mean a member. According to Sutter's Interface Principle
1. For a class X, all functions, including free functions, that both
"mention X" and are "supplied with" X (ie. the function and X are in
the same namespace/header file) are logically part of X, because they
form part of the interface of X.
2. Therefore, both member and nonmember functions can be logically
"part of" a class. A member function function is still more strongly
related to a class than is a nonmember, however.

Since my sqrt() is in another header file, is it still "part of" class
Vector? And does it matter anyway and this interface principle stuff??
My program works fine as it is.

 
Reply With Quote
 
Victor Bazarov
Guest
Posts: n/a
 
      08-12-2005
(E-Mail Removed) wrote:
> [...]
> Since my sqrt() is in another header file, is it still "part of" class
> Vector?


If you consider it interface, it's interface. If the user of your class
will need to include other headers to complete the declarations of the
interface, so what?

> And does it matter anyway and this interface principle stuff??
> My program works fine as it is.


It probably doesn't matter.

Now I am puzzled a little bit. If you are quoting Sutter's interface
principle, you must agree with it, no? If you agree with it, what made
you ask the question you asked? I mean, do you still have doubts about
your 'sqrt' template's being part of 'Vector's interface? What causes
those doubts?

V
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Principle Engineer needed Joe Feldman C++ 14 05-06-2010 12:47 AM
Liskov Substitution Principle mailforpr@googlemail.com C++ 11 10-14-2006 09:52 PM
Webmessenger principle CW ASP .Net 5 09-23-2004 02:14 AM
Dependency Inversion Principle Dilemma Thomas Matthews C++ 12 12-23-2003 08:51 PM
principle of stport std::sort Pavel Pluhacek C++ 2 09-01-2003 05:37 PM



Advertisments