Sign in to follow this  

Structure of library

This topic is 4209 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm doing a little refactoring at the moment, because I don't like how my libraries are structured. There's no problem with their respective roles, the problem is mainly the point of access. At the moment each library is effectively encapsulated in a class, which is a Singleton (oh noes!). The thing is, I want to hide my members from everyone, whilst really only providing one point of access to them. And preferably one instance - you see, it is effectively a "mega-class" at the moment, albeit a very small one. That too can/should change. Does anybody have a suggestion?

Share this post


Link to post
Share on other sites
Quote:
Original post by phantom
why are you imposing singletons on the user of the library?


Quote:
Original post by _goat
The thing is, I want to hide my members from everyone, whilst really only providing one point of access to them. And preferably one instance - you see, it is effectively a "mega-class" at the moment, albeit a very small one.

Share this post


Link to post
Share on other sites
Libraries that do not use singletons generally have to be "started" by using some type of "init" or "startup" static function which create a set hidden static/global data types that subsequent API calls use. They tend to require a static "shutdown" or "close" functions to cleanup the stuff they made during execution. Personnally I dont see this as being less "imposing" than using a singleton but you can do whatever you want. Documentation is the most important "structure" of any library. If you use a singleton explain why and how to use it. Its your library, you have a much more intimate view of the code than any other programmer that uses the library, design the best way you see fit. Also, in general, singletons can easily be refactored to non-singleton classes.

However, about 90% of the singletons I have seen are not thread safe.
http://www.oaklib.org/docs/oak/singleton.html.

Share this post


Link to post
Share on other sites

This topic is 4209 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this