From: linq936 on
Hi,

I have a c++ class like this:

class AddressTable{
...some specific address table data structure definition...

... some member functions ...
}

I need to add some more functionalities around this class. There is
one restrictioin though -- I can not change anything of this class,
interface, implementation, whatsoever.

I plan to do create a utility class whose member functions are all
static until the following 2 functions come to me:

static int AddressTableUtil::addConfliction(...some data...);
static int AddressTableUtil::resolveConfliction();

You can see these 2 functions are related, the first function adds
some data to some data structure and the second is to operate on that
data structure.

I do not want to add a static member variable to the utility class.

My solution is to create a new class,
AddressTableConflictionResolver.

class AddressTableConflictionResolver{
...definition of a data structure...

public:
AddressTableConflictionResolver();
~AddressTableConflictionResolver();

int addConfliction(...some data...);
int resolveConfliction();
}

This basically change a group of static utility functions into a
class.

Do you see any problem doing this?



From: Daniel T. on
linq936 <linq936(a)gmail.com> wrote:

> I have a c++ class like this:
>
> class AddressTable{
> ...some specific address table data structure definition...
>
> ... some member functions ...
> }
>
> I need to add some more functionalities around this class. There is
> one restrictioin though -- I can not change anything of this class,
> interface, implementation, whatsoever.
>
> I plan to do create a utility class whose member functions are all
> static until the following 2 functions come to me:
>
> static int AddressTableUtil::addConfliction(...some data...);
> static int AddressTableUtil::resolveConfliction();
>
> You can see these 2 functions are related, the first function adds
> some data to some data structure and the second is to operate on that
> data structure.
>
> I do not want to add a static member variable to the utility class.
>
> My solution is to create a new class,
> AddressTableConflictionResolver.
>
> class AddressTableConflictionResolver{
> ...definition of a data structure...
>
> public:
> AddressTableConflictionResolver();
> ~AddressTableConflictionResolver();
>
> int addConfliction(...some data...);
> int resolveConfliction();
> }
>
> This basically change a group of static utility functions into a
> class.
>
> Do you see any problem doing this?

Can a single AddressTableConflictionResolver be used to modify two or
more different AddressTables? If not, then I don't like your idea.
Better would be to wrap the AddressTable in an Adaptor.

class AddressTableAdaptor {
AddressTable addressTable;
// extra data relating to conflicts
public:
// some functions delegate straight to the addressTable
int addConfliction( /*some data*/ );
int resolveConfliction(); // what do these functions return?
};
From: linq936 on
On Dec 31, 9:19 am, "Daniel T." <danie...(a)earthlink.net> wrote:
> linq936<linq...(a)gmail.com> wrote:
> >   I have a c++ class like this:
>
> >   class AddressTable{
> >      ...some specific address table data structure definition...
>
> >      ... some member functions ...
> >   }
>
> >   I need to add some more functionalities around this class. There is
> > one restrictioin though -- I can not change anything of this class,
> > interface, implementation, whatsoever.
>
> >   I plan to do create a utility class whose member functions are all
> > static until the following 2 functions come to me:
>
> >   static int AddressTableUtil::addConfliction(...some data...);
> >   static int AddressTableUtil::resolveConfliction();
>
> >   You can see these 2 functions are related, the first function adds
> > some data to some data structure and the second is to operate on that
> > data structure.
>
> >   I do not want to add a static member variable to the utility class.
>
> >   My solution is to create a new class,
> > AddressTableConflictionResolver.
>
> >   class AddressTableConflictionResolver{
> >      ...definition of a data structure...
>
> >     public:
> >     AddressTableConflictionResolver();
> >     ~AddressTableConflictionResolver();
>
> >     int addConfliction(...some data...);
> >     int resolveConfliction();
> >   }
>
> >   This basically change a group of static utility functions into a
> > class.
>
> >   Do you see any problem doing this?
>
> Can a single AddressTableConflictionResolver be used to modify two or
> more different AddressTables? If not, then I don't like your idea.
> Better would be to wrap the AddressTable in an Adaptor.
>
> class AddressTableAdaptor {
>    AddressTable addressTable;
>    // extra data relating to conflicts
> public:
>    // some functions delegate straight to the addressTable
>    int addConfliction( /*some data*/ );
>    int resolveConfliction(); // what do these functions return?
>
> };

Thanks for your reply.

Yes, the resolver works on multiple AddressTable, so adapter does not
work here.
From: Daniel T. on
linq936 <linq936(a)gmail.com> wrote:
> "Daniel T." <danie...(a)earthlink.net> wrote:
> > linq936<linq...(a)gmail.com> wrote:

> > > � I have a c++ class like this:
> >
> > > � class AddressTable{
> > > � � �...some specific address table data structure definition...
> >
> > > � � �... some member functions ...
> > > � }
> >
> > > � I need to add some more functionalities around this class. There is
> > > one restrictioin though -- I can not change anything of this class,
> > > interface, implementation, whatsoever.
> >
> > > � I plan to do create a utility class whose member functions are all
> > > static until the following 2 functions come to me:
> >
> > > � static int AddressTableUtil::addConfliction(...some data...);
> > > � static int AddressTableUtil::resolveConfliction();
> >
> > > � You can see these 2 functions are related, the first function adds
> > > some data to some data structure and the second is to operate on that
> > > data structure.
> >
> > > � I do not want to add a static member variable to the utility class.
> >
> > > � My solution is to create a new class,
> > > AddressTableConflictionResolver.
> >
> > > � class AddressTableConflictionResolver{
> > > � � �...definition of a data structure...
> >
> > > � � public:
> > > � � AddressTableConflictionResolver();
> > > � � ~AddressTableConflictionResolver();
> >
> > > � � int addConfliction(...some data...);
> > > � � int resolveConfliction();
> > > � }
> >
> > > � This basically change a group of static utility functions into a
> > > class.
> >
> > > � Do you see any problem doing this?
> >
> > Can a single AddressTableConflictionResolver be used to modify two or
> > more different AddressTables?
>
> Yes, the resolver works on multiple AddressTable...

Then, baring some other issue that I'm not seeing in your presentation.
Making the class like you have is fine.