473,396 Members | 1,915 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

interface principle

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?

Aug 12 '05 #1
3 1476
bl**********@gmail.com 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
Aug 12 '05 #2
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.

Aug 12 '05 #3
bl**********@gmail.com 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
Aug 12 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: The Directive | last post by:
Is there a way in C++ to create a "true" interface. I want to create an absract class that other classes can inherit from and be forced to implement the interface's abstract (pure virtual) methods....
26
by: Marius Horak | last post by:
As in subject. Thanks MH
4
by: jm | last post by:
Consider: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon/html/vbconwhenshouldiimplementinterfacesinmycomponent.asp // Code for the IAccount interface module. public...
47
by: Matthew | last post by:
I am just about finished my first Visual Basic program. Yay! Does anybody had any suggestions about improving the look of the interface? I have read that programmers tend to have a cluttered...
3
by: Martin Arvidsson \(Visual Systems AB\) | last post by:
Hi! I realy dont get the point of interfaces If i have this code Public class MyClass { Public MyClass() {
0
by: YellowFin Announcements | last post by:
Introduction Usability and relevance have been identified as the major factors preventing mass adoption of Business Intelligence applications. What we have today are traditional BI tools that...
5
by: g18c | last post by:
Hi, im trying to do something and just been caught off guard. I want to implement an interface but only for certain class, but of course when i derive from this base class the derived class also...
2
by: Diego F. | last post by:
I need to make a windows service that shows the process in a window. How can I add an interface to a windows service? -- Regards, Diego F.
52
by: Ben Voigt [C++ MVP] | last post by:
I get C:\Programming\LTM\devtools\UselessJunkForDissassembly\Class1.cs(360,27): error CS0535: 'UselessJunkForDissassembly.InvocableInternals' does not implement interface member...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.