interface principle

Discussion in 'C++' started by bluekite2000@gmail.com, Aug 12, 2005.

  1. Guest

    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, 2005
    #1
    1. Advertising

  2. 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
     
    Victor Bazarov, Aug 12, 2005
    #2
    1. Advertising

  3. Guest

    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, 2005
    #3
  4. 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
     
    Victor Bazarov, Aug 12, 2005
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. CW

    Webmessenger principle

    CW, Sep 22, 2004, in forum: ASP .Net
    Replies:
    5
    Views:
    685
    Steven Cheng[MSFT]
    Sep 23, 2004
  2. Pavel Pluhacek

    principle of stport std::sort

    Pavel Pluhacek, Sep 1, 2003, in forum: C++
    Replies:
    2
    Views:
    420
    llewelly
    Sep 1, 2003
  3. Thomas Matthews

    Dependency Inversion Principle Dilemma

    Thomas Matthews, Dec 18, 2003, in forum: C++
    Replies:
    12
    Views:
    643
    Mike Smith
    Dec 23, 2003
  4. Joe Feldman

    Principle Engineer needed

    Joe Feldman, Sep 28, 2004, in forum: C++
    Replies:
    14
    Views:
    9,087
    nenupharvn
    May 6, 2010
  5. Replies:
    11
    Views:
    607
Loading...

Share This Page