Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Issue Regarding Classes and Objects

former_member226225
Contributor
0 Likes
818

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

1 ACCEPTED SOLUTION
Read only

Kiran_Valluru
Active Contributor
0 Likes
771

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

6 REPLIES 6
Read only

Kiran_Valluru
Active Contributor
0 Likes
772

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

Read only

0 Likes
771

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

Read only

0 Likes
771

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

Read only

0 Likes
771

Thanks Priyanka

Read only

Former Member
0 Likes
771

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.

Design pattern

Thanks..

~Raj

Read only

Former Member
0 Likes
771

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.