From: K�r�at on
Hi All,

I may be in search of impossibility but I thing this is worth asking :

Almost every developers define classes and use them in anothers. If A is a
class and B uses A then we can name B as outer class and A as inner class.

We will make some assumptons at this time :
- Outer class and inner class both has a method named initialize,
- Outer class can define many inner class objects,
- In its initialize method, outer class should call the initialize method of
every inner class objects,

It is highly possible to define an inner class object but forget to call its
initialize method in the outer object's initialize method. I need a compile
time (some runtime solutions already at hand)coupling mechanism to warn
developer about missing method calls. Do you have any idea?

(I am using Visual Studio Team System 2008 Development Edition.)

Thanks in advance


From: Vladimir Grigoriev on
Include an initializing method into the constructor of your inner object.

Vladimir Grigoriev

"K�r�at" <xx(a)yy.com> wrote in message
news:et5XtxctIHA.2064(a)TK2MSFTNGP05.phx.gbl...
> Hi All,
>
> I may be in search of impossibility but I thing this is worth asking :
>
> Almost every developers define classes and use them in anothers. If A is a
> class and B uses A then we can name B as outer class and A as inner class.
>
> We will make some assumptons at this time :
> - Outer class and inner class both has a method named initialize,
> - Outer class can define many inner class objects,
> - In its initialize method, outer class should call the initialize method
> of every inner class objects,
>
> It is highly possible to define an inner class object but forget to call
> its initialize method in the outer object's initialize method. I need a
> compile time (some runtime solutions already at hand)coupling mechanism to
> warn developer about missing method calls. Do you have any idea?
>
> (I am using Visual Studio Team System 2008 Development Edition.)
>
> Thanks in advance
>


From: K�r�at on
"initialize" method can be called at any time, not just construction phase.
The name "initialize" recalls constructors so it may be better to name it as
"reset" :)

"Vladimir Grigoriev" <vlad.moscow(a)mail.ru> wrote in message
news:emL$33ctIHA.552(a)TK2MSFTNGP06.phx.gbl...
> Include an initializing method into the constructor of your inner object.
>
> Vladimir Grigoriev
>
> "K�r�at" <xx(a)yy.com> wrote in message
> news:et5XtxctIHA.2064(a)TK2MSFTNGP05.phx.gbl...
>> Hi All,
>>
>> I may be in search of impossibility but I thing this is worth asking :
>>
>> Almost every developers define classes and use them in anothers. If A is
>> a class and B uses A then we can name B as outer class and A as inner
>> class.
>>
>> We will make some assumptons at this time :
>> - Outer class and inner class both has a method named initialize,
>> - Outer class can define many inner class objects,
>> - In its initialize method, outer class should call the initialize method
>> of every inner class objects,
>>
>> It is highly possible to define an inner class object but forget to call
>> its initialize method in the outer object's initialize method. I need a
>> compile time (some runtime solutions already at hand)coupling mechanism
>> to warn developer about missing method calls. Do you have any idea?
>>
>> (I am using Visual Studio Team System 2008 Development Edition.)
>>
>> Thanks in advance
>>
>
>
>


From: Igor Tandetnik on
Krat <xx(a)yy.com> wrote:
> "initialize" method can be called at any time, not just construction
> phase. The name "initialize" recalls constructors so it may be better
> to name it as "reset" :)

Use Pimp idiom to implement the outer class. Then Reset is simply

void B::Reset() {
BImpl* newImpl = new BImpl;
delete pimpl_;
pimpl_ = newImpl;
}

which would run the constructor of BImpl and all its "inner" objects.
--
With best wishes,
Igor Tandetnik

With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925


From: Ondrej Spanel on
For a similar case of derived classes (not encapsulated objects) I think
following could work quite well: the helper object HiddenValue which can
be created only in the Base class, all other classes need to use Func to
create it. If you need to return some return value from the function it
may get more complicated, but you should always be able to solve this
with an additional argument.

I am not sure if you will be able to adapt this to inner objects, though.

(Sidenote: To me a surprise was that if I wanted the ForceBase Func(){}
variant to trigger an error, I had to use the function. Without the main
it did not fail. I guess something to do with how VC instantiates
inlined functions)

Ondrej
-----------

class Base
{
public:
class ForceBase
{
friend Base;

private:
ForceBase(){}
};

ForceBase Func()
{
return ForceBase();
}
};

class Derived: public Base
{
public:
//ForceBase Func() {return ForceBase();} // error
//ForceBase Func(){} // error
ForceBase Func() {return Base::Func();} // OK
};

int main(int argc, const char * argv[])
{
Derived a;
a.Func();
return 0;
}



K�r�at napsal(a):
> "initialize" method can be called at any time, not just construction phase.
> The name "initialize" recalls constructors so it may be better to name it as
> "reset" :)
>
> "Vladimir Grigoriev" <vlad.moscow(a)mail.ru> wrote in message
> news:emL$33ctIHA.552(a)TK2MSFTNGP06.phx.gbl...
>> Include an initializing method into the constructor of your inner object.
>>
>> Vladimir Grigoriev
>>
>> "K�r�at" <xx(a)yy.com> wrote in message
>> news:et5XtxctIHA.2064(a)TK2MSFTNGP05.phx.gbl...
>>> Hi All,
>>>
>>> I may be in search of impossibility but I thing this is worth asking :
>>>
>>> Almost every developers define classes and use them in anothers. If A is
>>> a class and B uses A then we can name B as outer class and A as inner
>>> class.
>>>
>>> We will make some assumptons at this time :
>>> - Outer class and inner class both has a method named initialize,
>>> - Outer class can define many inner class objects,
>>> - In its initialize method, outer class should call the initialize method
>>> of every inner class objects,
>>>
>>> It is highly possible to define an inner class object but forget to call
>>> its initialize method in the outer object's initialize method. I need a
>>> compile time (some runtime solutions already at hand)coupling mechanism
>>> to warn developer about missing method calls. Do you have any idea?
>>>
>>> (I am using Visual Studio Team System 2008 Development Edition.)
>>>
>>> Thanks in advance
>>>
>>
>>
>
>