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

Library I/F design policy

I've got an old C arithmetic library that I want to convert to C++.
There are about 30 routines, which all take pointers to an arithmetic
structure.

I'd like to convert this to C++, so that the user sees only a new
arithmetic class, with overloaded arithmetic ops (+/-/etc) which call
the old C code under the hood. The user doesn't need to see the old C
code. The new class contains only a few fields, and the user doesn't
need to see these either.

The problem is, I can see 2 or 3 ways to do this, and it's starting to
get messy. Any advice on how to do this? I'm currently using
combinations of these 3:

1 - The C functions are all private member methods, with direct access
to the new fields. This is the easiest, but may have long-term
maintenance problems. The library user also finds out about the
existence of the C routines, since they're declared in the class
header. This is not really a problem, but I'd prefer the header to be
clean.

2 - The C functions are all external, in their own namespace, and the
class declares them as friends, so they can still see the class
internals. Again, perhaps not good in the long term.

3 - The C functions are again all external, in their own namespace. I
now have access methods for all the private class fields, and the C++
and C code is modified to use these access methods. This is messy, but
I suppose it's the Right Thing to do.

?

Thanks -

Paul
Jun 14 '07 #1
3 1101
And should I make the new operators members or non-members?

Thanks -

Paul
Jun 14 '07 #2
On Jun 14, 6:25 pm, Paul French <pf9...@yahoo.comwrote:
And should I make the new operators members or non-members?

Thanks -

Paul
Dear Paul,

I will suggest you a different method.
You can make a call which contains just API's.
And another class will have calls to C functions corresponding to
each API.
So you will have a class ArithmaticAPI and a class
ArithmaticManager.
ArithmaticManager's object is created in ArithmaticAPI and the user
only need to know about the class ArithmaticAPI.
You can either make the C language code as a private member of
ArithmaticManager or you can make those function's friends.

eg:

ArithmaticManager.h

class ArithmaticManager
{
public:
int Greatest( int, int );
int Smallest( int, int );
};

ArithmaticAPI.h

#include ArithmaticManager.h
class ArithmaticAPI
{
private:
ArithmaticManager m_ArithmaticMgr;
public:
int Greatest( int a, int b ){ return
m_ArithmaticMgr.Greatest(); }
int Smallest( int a, int b ){ return
m_ArithmaticMgr.Smallest(); }
}
Even the member of ArithmaticManager need not have to be created
provided you declare ArithmaticManager functions as static ones.

Thanks and regards,
Amal P

Jun 14 '07 #3
On Jun 14, 7:36 pm, Amal P <enjoyam...@gmail.comwrote:
On Jun 14, 6:25 pm, Paul French <pf9...@yahoo.comwrote:
And should I make the new operators members or non-members?
Thanks -
Paul

Dear Paul,

I will suggest you a different method.
You can make a call which contains just API's.
And another class will have calls to C functions corresponding to
each API.
So you will have a class ArithmaticAPI and a class
ArithmaticManager.
ArithmaticManager's object is created in ArithmaticAPI and the user
only need to know about the class ArithmaticAPI.
You can either make the C language code as a private member of
ArithmaticManager or you can make those function's friends.

eg:

ArithmaticManager.h

class ArithmaticManager
{
public:
int Greatest( int, int );
int Smallest( int, int );
};

ArithmaticAPI.h

#include ArithmaticManager.h
class ArithmaticAPI
{
private:
ArithmaticManager m_ArithmaticMgr;
public:
int Greatest( int a, int b ){ return
m_ArithmaticMgr.Greatest(); }
int Smallest( int a, int b ){ return
m_ArithmaticMgr.Smallest(); }
}

Even the member of ArithmaticManager need not have to be created
provided you declare ArithmaticManager functions as static ones.

Thanks and regards,
Amal P
You can overload operator as either member or friends.

Jun 14 '07 #4

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

Similar topics

51
by: Reinhold Birkenfeld | last post by:
Hello, at the moment python-dev is discussing including Jason Orendorff's path module into the standard library. Do you have any other good and valued Python modules that you would think are...
7
by: Adrian | last post by:
Normalization Question - Please bear with me, hopefully things will be clear at the end of the question. Given a treaty table containg treaties; Treaty1, Treaty2 etc and a benefit table;...
9
by: Martin Vorbrodt | last post by:
I'm designing a Matrix class of 4x4 matrices used in computer graphics. Both OpenGL and Direct3D can take a pointer to array of 16 floats which represent the values in the matrix. OGL takes it in...
4
by: Erik Wikström | last post by:
In school (no I will not ask you to do my schoolwork for me) we talked about policy-based design and got an assignment where we got the a code- fragment from a stack-implementation. The idea with...
1
by: Nick | last post by:
I have read a few months ago about a policy design pattern but can find nothing on it now. Does this design pattern exist and if so could someone explain what it is or links to a description. ...
15
by: xargon | last post by:
Hi everyone, I am writing a small user interface library in C++ (I know it has been done to death, but it is good for learning ). Anyways, I need some help/advice with the deisgn of the...
0
by: John Dalberg | last post by:
I am getting the error below many times when I am trying to use the Enterprise Library. The solution seems to be a reboot. I am using Windows 2003 as my dev box. The error also happens with other...
2
by: Steve | last post by:
I want to call my web service from a class library and have that library handle all the wse stuff, so that applications using that library don't have to worry about it. Is that possible? I've...
0
by: =?Utf-8?B?YW5rMmdv?= | last post by:
Hi, Thanks in advance for reading this. Not sure where to post this question, but I hope someone in here can help. Trying to write to Event Log in VS 2005 (.NET 2.0) using Enterprise Library...
0
by: =?Utf-8?B?UG9sbHkgQW5uYQ==?= | last post by:
Hi, I have previously used EL v 3.1 Exception Handling application block successfully. I thought I would now try to do the same with EL v 4.0. My first experiment was to replace an exception....
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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...

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.