2005 Sep 13 10:43 AM
Hi folks,
I'd like to create a factory method in a class. The factory method returns objects (corresponding to certain keys) of the class by first checking an internal map for the key and then returning the pertaining object if an entry for that key exists or creating a new object (and putting it into the table) if it doesn't.
Now I wanted to declare the actual constructor <i>private</i>, but found SE80 prohibits changing the accessibility of constructors - there are always public?!
Is there a way to achieve private accessibility of constructors, what does <i>Instantiation - private</i> on the properties tab of a class mean (as opposed to possibly changing the constructor to private)?
Great if someone could shed some light onto this.
Regards,
Sebastian
2005 Sep 13 12:24 PM
since you can not call the constructor directly there is no need to declare the constructor as private.
To avoid that an instance can be created from outside the class jsut declare it as
class lcl_class definition create private.
or if it is global:
go to tab properties and set choose private in the instantiation.
sorry just realised that you were asking exactly that question.
With create private only methods of this class can create an instance of this class.
create proteced extends it to inherited classes and public means that every method can create instances.
Christian
Message was edited by: Christian Finkbeiner
Hi folks,
I'd like to create a factory method in a class. The factory method returns objects (corresponding to certain keys) of the class by first checking an internal map for the key and then returning the pertaining object if an entry for that key exists or creating a new object (and putting it into the table) if it doesn't.
Now I wanted to declare the actual constructor <i>private</i>, but found SE80 prohibits changing the accessibility of constructors - there are always public?!
Is there a way to achieve private accessibility of constructors, what does <i>Instantiation - private</i> on the properties tab of a class mean (as opposed to possibly changing the constructor to private)?
Great if someone could shed some light onto this.
Regards,
Sebastian
2005 Sep 13 12:24 PM
since you can not call the constructor directly there is no need to declare the constructor as private.
To avoid that an instance can be created from outside the class jsut declare it as
class lcl_class definition create private.
or if it is global:
go to tab properties and set choose private in the instantiation.
sorry just realised that you were asking exactly that question.
With create private only methods of this class can create an instance of this class.
create proteced extends it to inherited classes and public means that every method can create instances.
Christian
Message was edited by: Christian Finkbeiner
2005 Sep 13 12:47 PM
> since you can not call the constructor directly there
> is no need to declare the constructor as private.
well, that is almost a philosophical question. I mean in a way I do call the constructor directly: it is called immediately after using the <i>create object</i> command.. but I know what you mean
> To avoid that an instance can be created from outside
> the class jsut declare it as
> class lcl_class definition create private.
>
> or if it is global:
> go to tab properties and set choose private in the
> instantiation.
> ...
> With create private only methods of this class can
> create an instance of this class...
That is, only methods of this class can call the constructor (use <i>create object</i>), right?
This would indeed have the desired effect that creation of this class' objects (somewhere outside the class) was only possible through the factory and not by calling the constructor.
Thanks, Sebastian
2005 Sep 13 12:54 PM
I just tried to reward points for Christian's posting by marking the <i>problem solved</i> radiobutton, but I am constantly getting a "Rewarding the message failed."-error. Has someone an idea what could be wrong?
2005 Sep 13 3:31 PM
Yep you got me right and the points are assigned. Thank you
Christian