My scenario involves two classes and a database. I have the classes
"Broom" and "Closet". I want to use a static method from the "Closet"
class to search the database for a matching "Broom". If it finds a
matching "Broom", i want it to return a "Broom" object to the calling
program. I want the static method to call the constructor for the
"Broom" class. I want this static method, (and one other called
"CreateBroom") to be the only ones that can call the "Broom"
constructor. In other words, I don't want the "Broom" constructor to
be callable from the main program code.
I don't want to have the "Closet" class inherit from the "Broom" class,
(and thereafter make the "Broom" constructor protected) because I don't
want the other methods and properties of the "Broom" class to be
accessible from an instance of the "Closet" class.
I can't put the "Broom" class inside of the "Closet" class, (thereby
making it's constructor available only to the "Closet" methods) because
then a "Broom" object cannot be instantiated on it's own to the calling
program by the static method.
Please, any advice would be appreciated. If I am wrong on any points
or there are any alternatives that I have not considered, don't
hesitate to illuminate me.
Thank you.