2012 Dec 18 5:07 AM
Hi ,
We are creating Objects for Classes by using Create Object , for some classes we are creating like this and for some classes we are creating by using factory classes . I don't why we are creating objects by using factory classes and what is the differences in between them . For that classes also we can use syntax CREATE OBJECT ?
Thanks,
Raghunadh.K
2012 Dec 18 3:12 PM
Hi,
For that classes also we can use syntax CREATE OBJECT ?No. They might be private classes(following singleton pattern). Please search for Singleton design pattern for more information.
Try using create object for those classes. You will get error message which will explain you in more detail.
Regards,
Kiran
2012 Dec 18 3:12 PM
Hi,
For that classes also we can use syntax CREATE OBJECT ?No. They might be private classes(following singleton pattern). Please search for Singleton design pattern for more information.
Try using create object for those classes. You will get error message which will explain you in more detail.
Regards,
Kiran
2012 Dec 19 6:30 AM
Hi Kiran,
Thanks for your reply , so i have to check the Visibility sections of the class before creating object so based upon that i have to create object ?
Thanks,
Raghunadh.K
2012 Dec 19 8:12 AM
Hi,
For Global class:
You need to check in SE24 the instance Generation field. If it is Private than you will that such class will have a factory method.
Most used example: class CL_SALV_TABLE. Check it's properties in SE24.
For local class:
You need to see there the class definition. There is option of CREATE public/private/protected...
If this create option is private you need a factory method
Regards,
Priyanka
2012 Dec 19 8:31 AM
2012 Dec 19 8:29 AM
Hi ,
Creation of object , visibility all is part of design patterns .
Factory classes and methods are one of the most useful design pattern.
below article might be useful and give you a clear understanding how it can be useful.
Thanks..
~Raj
2013 Feb 01 12:29 PM
Hi,
Factory methods are there to control instantiation of a class. They are there because creator of class doesnt want everyone to have authority to create its object.
Factory methods instantiate the class with CREATE OBJECT and provide you the reference to the object.
They provide various functionalities like :
>Singleton class - Only one instantiation allowed.
>Checking if object with the parameter values provided exists already.
When defining a class, additions [CREATE PUBLIC][CREATE PRIVATE][CREATE PROTECTED] decide who can instantiate the class with CREATE OBJECT statement.
CREATE PUBLIC - anyone can instantiate with CREATE OBJECT.
CREATE PRIVATE - only the class itself or friend class can instantiate with CREATE OBJECT.
CREATE PROTECTED - only the class itself or sub-classes can instantiate with CREATE OBJECT.
Classes with [CREATE PRIVATE] have factory methods in itself as static methods or implemented in friend class as a friend class can access all sections of the class.
eg.: CLASS lcl_abc DEFINITION CREATE PRIVATE.
.....
.....
ENDCLASS.
This class can only be instantiated by itself or friend class. You cant use CREATE OBJECT in your main program or anywhere else to instantiate it.