What is the procedure for a class that meets the following criteria:
1. May be called from many other classes
2. Generally, only 1 instance is needed, but sometimes more (ie cannot be a Singleton
3. Has already been instantiated before any other classes
Using a global var would be easy but I'm not sure that is the proper method.
I don't want to instantiate it everytime I need it, but sometimes I will need to have 2 or more copies of it running concurrently. Would it be best to simply make a copy of it?
EDIT: Also, what would be the best way to call this class from other classes?
Global Class
Moderator: General Moderators
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
A class that can have one or more instantiated objects and is not a Singleton is just a plain old class. If you want it created before it is used then you have the option of creating an instance and passing it into where you will use it either directly or via a Registry/Factory. You can also Lazy load the class/object by supplying the "wiring" to instansiate it to something like Service Locator and then it will be created the first time it is asked for.
(#10850)
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia