473,811 Members | 2,911 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Code specific to couples of classes

dl
I'll try to clarify the cryptic subject line.

Let's say I have a base class 'GeometricObjec t' with a virtual method
'double distance (const GeometricObject &) const'.

Among the derived classes I have eg 'Segment', representing a segment
of a line, and 'Arc', representing an arc of circle.

What is the right place to put the code for computing the distance
between a Segment and an Arc? It is not specific to the Segment nor to
the Arc, but to the coupling of the two objects.

Thank you,

Daniele

Mar 4 '07
19 1838
On 6 Mar, 18:04, "Grizlyk" <grizl...@yande x.ruwrote:
Gavin Deane wrote:
Alan Johnson wrote:
If you want some authoritative word on that try Item 23 of Scott
Meyer's
Effective C++: "Prefer non-member non-friend functions to member
functions."
I do not know what Scott Meyer meant but think, it is not general rule.
Member function can have encapsulated data so member function can be
better than plain function.
He meant this
http://www.ddj.com/dept/cpp/184401197

1.
He has written: "It's important that we're trying to choose between member
functions and non-friend non-member functions".

As i can understand "non-friend non-member function" is a function, that can
use only public interface of the class.
No. A non-member non-friend *is part of* the interface. It operates on
objects through the public member functions, which are another part of
the interface. The whole point of that article is that it is a mistake
to think that public member functions are the only thing that make up
a class's interface.

Read the first paragraph under the heading Interfaces and Packaging.

<snip>
He has written: "it becomes clear that a class with n member functions is
more encapsulated than a class with n+1 member functions". Maybe he want to
say, that small interface is better than large one.
No, that's missing the point. A class with n public member functions
plus 1 non-member non-friend function that works with those public
member functions has exactly the same size interface as a class with n
+1 public member functions. But the former is a more encapsulated
interface.

Gavin Deane

Mar 6 '07 #11
Grizlyk wrote:
>
template<
class First,
class Second,
class Dist_implementa tion=
Ndecl::Dist_imp lementation<Fir st,Second>
>
type distance(const Second& obj)
Surprise, surprise!
"default template arguments may not be used in function templates"

No one can predict the limitation, of course, becasue no reasons to enable
defaults for classes, but disable it for functions. You can make class here:

//declaration
template<
class First,
class Second,
class Dist_implementa tion=
Ndecl::Dist_imp lementation<Fir st,Second>
>
struct Tdummy
{
type distance(const Second& obj){...
};

//usage
GeometricObject ::Tdummy<First, Second dummy;
dummy.distance( ...

GeometricObject ::
Tdummy<First, Second, New_Dist_implem entation>
dummy;

dummy.distance( ...

--
Maksim A. Polyanin
http://grizlyk1.narod.ru/cpp_new

"In thi world of fairy tales rolls are liked olso"
/Gnume/
Mar 7 '07 #12
Gavin Deane wrote:
>>
>Alan Johnson wrote:
If you want some authoritative word on that try Item 23 of Scott
Meyer's Effective C++: "Prefer non-member non-friend functions
to member functions."
>I do not know what Scott Meyer meant but think, it is not general
rule.
Member function can have encapsulated data so member function can be
better than plain function.
He meant this
http://www.ddj.com/dept/cpp/184401197

1.
He has written: "It's important that we're trying to choose between
member
functions and non-friend non-member functions".

As i can understand "non-friend non-member function" is a function, that
can
use only public interface of the class.

No. A non-member non-friend *is part of* the interface. It operates on
objects through the public member functions, which are another part of
the interface. The whole point of that article is that it is a mistake
to think that public member functions are the only thing that make up
a class's interface.
It is standard OO convention "to thing that class's interface is only class
members". We can speak about namespace as a kind of opened interface, about
two classes, representing solid interface and so on, but there are other
things, another terms, not "class's interface".

--
Maksim A. Polyanin
http://grizlyk1.narod.ru/cpp_new

"In thi world of fairy tales rolls are liked olso"
/Gnume/
Mar 7 '07 #13
On 7 Mar, 09:55, "Grizlyk" <grizl...@yande x.ruwrote:
Gavin Deane wrote:
Alan Johnson wrote:
If you want some authoritative word on that try Item 23 of Scott
Meyer's Effective C++: "Prefer non-member non-friend functions
to member functions."
I do not know what Scott Meyer meant but think, it is not general
rule.
Member function can have encapsulated data so member function can be
better than plain function.
He meant this
http://www.ddj.com/dept/cpp/184401197
1.
He has written: "It's important that we're trying to choose between
member
functions and non-friend non-member functions".
As i can understand "non-friend non-member function" is a function, that
can
use only public interface of the class.
No. A non-member non-friend *is part of* the interface. It operates on
objects through the public member functions, which are another part of
the interface. The whole point of that article is that it is a mistake
to think that public member functions are the only thing that make up
a class's interface.

It is standard OO convention "to thing that class's interface is only class
members". We can speak about namespace as a kind of opened interface, about
two classes, representing solid interface and so on, but there are other
things, another terms, not "class's interface".
Well, my dictionary says that the verb "interface" means to interact.
So an interface of an object is the means with which we interact with
the object, be they member methods or not.

You can always be a purist and stick to some definition made by
someone sometime, but for the rest of the world a notation, such as
OO, changes over time (just as the meaning of words in natural
language) as new ways and uses are discovered. Personally I think it's
a good idea to include non-friend non-member functions in the
interface sine it makes a lot of classes more useful. Just look at
std::vector, it's a sequential container in which you can put/access/
remove thing and not much more. But if you add all the functionality
from <algorithmsit 's suddenly a lot more useful.

--
Erik Wikström

Mar 7 '07 #14
Erik Wikstrom wrote:
>>
>Alan Johnson wrote:
If you want some authoritative word on that try Item 23 of Scott
Meyer's Effective C++: "Prefer non-member non-friend functions
to member functions."
>I do not know what Scott Meyer meant but think, it is not general
rule.
Member function can have encapsulated data so member function can
be
better than plain function.
He meant this
http://www.ddj.com/dept/cpp/184401197
>1.
He has written: "It's important that we're trying to choose between
member
functions and non-friend non-member functions".
>As i can understand "non-friend non-member function" is a function,
that
can
use only public interface of the class.
No. A non-member non-friend *is part of* the interface. It operates on
objects through the public member functions, which are another part of
the interface. The whole point of that article is that it is a mistake
to think that public member functions are the only thing that make up
a class's interface.

It is standard OO convention "to thing that class's interface is only
class
members". We can speak about namespace as a kind of opened interface,
about
two classes, representing solid interface and so on, but there are other
things, another terms, not "class's interface".

You can always be a purist and stick to some definition made by
someone sometime, but for the rest of the world a notation, such as
OO, changes over time (just as the meaning of words in natural
language) as new ways and uses are discovered.
No, there is not "purism" here. The term "interface of class" means exactly
"some members of class". It you will use term "interface of class" as
"interface of namespace" you should invent new term for "interface of
class". And what is reason to do it? No reasons.
Personally I think it's a good idea to include non-friend non-member
functions
in the interface sine it makes a lot of classes more useful.
Yes, you can do including non-member functions into interface, but into
"interface of namespace", not into "interface of class".

Scott Meyer could say, that class must not be used separatedly, only with
its special namespace:

namespace Nclass_name{
class Tclass_name
{
public:
// some members
// are belonging to "interface of class Tclass_name"
// are belonging to "interface of namespace Nclass_name"
// as Tclass_name::fo o, Tclass_name::bo o
void foo();
void boo();
};

// some non-members
// are not belonging to "interface of class Tclass_name"
// but are belonging to "interface of namespace Nclass_name"
void foo(Tclass_name &);
void boo(Tclass_name &);

//namespace Nclass_name
}

and could say, that "interface of namespace Nclass_name" is more flexible
than interface of class Tclass_name", if he think so.

--
Maksim A. Polyanin
http://grizlyk1.narod.ru/cpp_new

"In thi world of fairy tales rolls are liked olso"
/Gnume/
Mar 7 '07 #15
On 7 Mar, 08:55, "Grizlyk" <grizl...@yande x.ruwrote:
GavinDeanewrote :
As i can understand "non-friend non-member function" is a function, that
can
use only public interface of the class.
No. A non-member non-friend *is part of* the interface. It operates on
objects through the public member functions, which are another part of
the interface. The whole point of that article is that it is a mistake
to think that public member functions are the only thing that make up
a class's interface.

It is standard OO convention "to thing that class's interface is only class
members".
So what? It's that very convention that the article questions (at
least in its applicability to C++). You can take issue with Scott
Meyers' arguments and decide for yourself whether you agree with his
conclusions (personally I find his arguments compelling) but it's not
reasonable to dismiss the entire article solely on the grounds that
it's questioning a convention in the first place. What's wrong with
questioning a convention? How else would you know whether it's
appropriate?

Gavin Deane

Mar 7 '07 #16
Gavin Deane wrote:
>
>As i can understand "non-friend non-member function" is a function,
that
can
use only public interface of the class.
No. A non-member non-friend *is part of* the interface. It operates on
objects through the public member functions, which are another part of
the interface. The whole point of that article is that it is a mistake
to think that public member functions are the only thing that make up
a class's interface.

It is standard OO convention "to thing that class's interface is only
class
members".

So what?
Nothing, for the name nothing, except he can find people do not understand
what he has said.

But for the idea, i am afraid (i am speaking about traditional "interface of
class" as "members of class"):
>Somebody could think, that if implementation of a member can be separated
from class, than interface _must_ be separated also (member removed as
_not
strictly necessary_). It is not true in general.
I do not like, that his advice looks like he digs into implementation
details in order to make interface, because it is bad idea. I think he could
say, that he try to change interface, after "interface of class" has been
logically completed, so he has no any other criterions to make the
interface, he can improve the interface in free manner.

For the case of "unspecifie d interface" i can not agree or disagree, because
do not know what we must do in the case.
--
Maksim A. Polyanin
http://grizlyk1.narod.ru/cpp_new

"In thi world of fairy tales rolls are liked olso"
/Gnume/
Mar 8 '07 #17
On 8 Mar, 09:32, "Grizlyk" <grizl...@yande x.ruwrote:
Gavin Deane wrote:
It is standard OO convention "to thing that class's interface is only
class
members".
So what?

Nothing, for the name nothing, except he can find people do not understand
what he has said.
Well he openly acknowledges that he expects you to be surprised by his
headline. But he doesn't leave it as just a headline. There's a few
pages of justification that follows.
But for the idea, i am afraid (i am speaking about traditional "interface of
class" as "members of class"):
I first read Scott Meyers's article after reading this http://www.gotw.ca/gotw/084.htm
from Herb Sutter. It provides a more in-depth example of how your
traditional definition of a class's interface may not be the most
appropriate definition in C++, using a class we are all familiar with.

Gavin Deane

Mar 8 '07 #18
In article <es**********@a ioe.org>, gr******@yandex .ru says...

[ ... ]
No, there is not "purism" here.
That, at least, is true.
The term "interface of class" means exactly "some members of class".
That, OTOH, is not true. It never was, and being "pure" about it doesn't
change anything -- it's just plain wrong.
It you will use term "interface of class" as
"interface of namespace" you should invent new term for "interface of
class". And what is reason to do it? No reasons.
Actually, there are very good reasons for putting the entire interface
to a class in a single namespace. What's unreasonable is the belief that
the entire interface to a class must consist of member functions. This
belief simply lacks factual basis.

[ ... ]
Yes, you can do including non-member functions into interface, but into
"interface of namespace", not into "interface of class".
Wrong! The interface to a class can consist partly or even entirely of
non-member functions. What makes you think otherwise?

--
Later,
Jerry.

The universe is a figment of its own imagination.
Mar 9 '07 #19

Gavin Deane wrote:
>
>But for the idea, i am afraid (i am speaking about traditional "interface
of
class" as "members of class"):

I first read Scott Meyers's article after reading this
http://www.gotw.ca/gotw/084.htm
from Herb Sutter. It provides a more in-depth example of how your
traditional definition of a class's interface may not be the most
appropriate definition in C++, using a class we are all familiar with.
What do you think about my arguments? Do you agree that :
1.
>Somebody could think, that if implementation of a member can be separated
from class, than interface _must_ be separated also (member removed as
_not strictly necessary_). It is not true in general.
and
2.
>I do not like, that his advice looks like he digs into implementation
details in order to make interface, because it is bad idea.
or not?

--
Maksim A. Polyanin
http://grizlyk1.narod.ru/cpp_new

"In thi world of fairy tales rolls are liked olso"
/Gnume/
Mar 9 '07 #20

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

Similar topics

242
13474
by: James Cameron | last post by:
Hi I'm developing a program and the client is worried about future reuse of the code. Say 5, 10, 15 years down the road. This will be a major factor in selecting the development language. Any comments on past experience, research articles, comments on the matter would be much appreciated. I suspect something like C would be the best based on comments I received from the VB news group. Thanks for the help in advance James Cameron
45
3632
by: Steven T. Hatton | last post by:
This is a purely *hypothetical* question. That means, it's /pretend/, CP. ;-) If you were forced at gunpoint to put all your code in classes, rather than in namespace scope (obviously classes themselves are an exception to this), and 'bootstrap' your program by instantiating a single application object in main(), would that place any limitations on what you could accomplish with your program? Are there any benefits to doing things that...
2
3798
by: Bryan Olson | last post by:
The current Python standard library provides two cryptographic hash functions: MD5 and SHA-1 . The authors of MD5 originally stated: It is conjectured that it is computationally infeasible to produce two messages having the same message digest. That conjecture is false, as demonstrated by Wang, Feng, Lai and Yu in 2004 . Just recently, Wang, Yu, and Lin showed a short- cut solution for finding collisions in SHA-1 . Their result
8
3043
by: Paul Cochrane | last post by:
Hi all, I've got an application that I'm writing that autogenerates python code which I then execute with exec(). I know that this is not the best way to run things, and I'm not 100% sure as to what I really should do. I've had a look through Programming Python and the Python Cookbook, which have given me ideas, but nothing has gelled yet, so I thought I'd put the question to the community. But first, let me be a little more detailed...
20
23118
by: Steve Jorgensen | last post by:
A while back, I started boning up on Software Engineering best practices and learning about Agile programming. In the process, I've become much more committed to removing duplication in code at a much finer level. As such, it's very frustrating to be working in VBA which lacks inheritance, one of the more powerful tools for eliminating duplication at the level I'm talking about. I've recently come up with a technique to emulate one...
171
7827
by: tshad | last post by:
I am just trying to decide whether to split my code and uses code behind. I did it with one of my pages and found it was quite a bit of trouble. I know that most people (and books and articles) like it because you can split the code from the design. That is logical. But if you are the only one working on the code, it seem a little overkill. I use Dreamweaver to do my design and find it a bit of a hassle to have multiple files open...
10
2297
by: Noozer | last post by:
I'm writing an ASP application and have a noob question... I have a class that access an MS SQL database. I have another class also accesses an MS SQL database and this second class uses objects from the first class. I have a third class using the DB and objects of the second class. Each of these classes contain all the code needed to access the database and this means much duplicated code. What I'd like to know is if there is a way...
0
1010
by: Happy Married Couple | last post by:
You're about to discover the 'magic ingredients' that make some couples live happy and blissful marriages for DECADES and how you can too. Dear Friend, My name is Michael Webb. I DON'T have a doctorate in counseling, marriage studies and I DON'T host a radio call in show… but I DO have what most other relationship "experts” don’t have…a blissful marriage. Which is why hundreds of men and women ask for my relationship advice and have...
8
2986
by: Brad Walton | last post by:
Hello. First post, but been doing a bit of reading here. I am working on a project in Java, but decided to switch over to C# after seeing some of the additional features I can get from C#. One of the big changes I want to make is event-driven code (rather than the linear flow I had in Java). I have spent a week or so searching Google, talking to a couple of programming friends, and just chewing on it in my brain. I think I have an ok handle...
0
10392
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10403
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10136
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9208
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7671
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6893
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5555
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5693
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3868
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.