473,387 Members | 1,705 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,387 software developers and data experts.

Double getters

I'm wondering is there a way to avoid having "double" getters:

class A
{
Compo *_C;
public:
int Get_From_C();
....

int A::Get_From_C() { return _C->Get_Something(); }

This problem gets worse if A is derived from a base
class and only some derived classes have Compo class.
Then you need to write a virtual getter if some routine
requires the base handle.

Jan 26 '06 #1
1 1700
Krice wrote:
I'm wondering is there a way to avoid having "double" getters:

class A
{
Compo *_C;
First identifiers starting with an underscore and a capital letter are
reserved for the implementation. Change _C to _c or c_ or something
else.
public:
int Get_From_C();
...

int A::Get_From_C() { return _C->Get_Something(); }

This problem gets worse if A is derived from a base
class and only some derived classes have Compo class.
Then you need to write a virtual getter if some routine
requires the base handle.


That's just the price of encapsulation (see
http://www.parashift.com/c++-faq-lit....html#faq-7.4),
though you might improve things by refactoring your design. Compare
this article:

http://www.gotw.ca/publications/mill05.htm

Cheers! --M

Jan 26 '06 #2

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

Similar topics

27
by: Stuart Gerchick | last post by:
C++ Coding Standards : 101 Rules, Guidelines, and Best Practices by Herb Sutter, Andrei Alexandrescu is now a month or so away from release. What is people's opinion on this...is it going to be a...
32
by: kelvSYC | last post by:
I'm familiar with get and set function paradigms from Java, but what's the recommended design for such in C++? Should it be like so: foo& getFoo(); void setFoo(foo& f); or like so: foo&...
2
by: Lachlan Hunt | last post by:
Hi, In JavaScript 1.5, objects can use special getter and setter functions for properties. However, these only seem to be implemented in Gecko and, AFAICT, don't seem to be part of ECMAScript. ...
2
by: Wei Wang | last post by:
Greetings, I find the JavaScript's Object.prototype and getter/setter mechanism very nice. However, I need some help with extending an object with getters/setters in the derived class. For...
13
by: Neil Zanella | last post by:
Hello, It seems to me that C# properties are nothing more than syntactic sugar for getters and setters. I wonder whether others hold a different point of view. Basically, what more do they have...
112
by: mystilleef | last post by:
Hello, What is the Pythonic way of implementing getters and setters. I've heard people say the use of accessors is not Pythonic. But why? And what is the alternative? I refrain from using them...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...

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.