‎2014 Jul 01 8:05 AM
Hello,
Is in ABAP any possibility to declare classes in section "Class rel. local definitions" and declare public methods or public types with them? I want to create dozen classes and main class-factory which will return some of them by request. Create everything in public will takes a lot of time, and not so beatiful like(pseudo code):
Class zcl_factory.
Public section.
TYPES: t_point TYPE REF TO LOCAL CLASS lcl_point. " in my case it is about 50+ classes
CLASS-METHODS: get_point RETURNING VALUE(point) TYPE t_point.
EndClass.
And using:
DATA: lv_point TYPE zcl_factory=>t_point.
lv_point = zcl_factory=>get_point().
*do something with lv_point
‎2014 Jul 01 1:59 PM
Hi Egor,
can you point out, wehre in your opinion is the added value for use of local classes in your scenario?
Actually, i have some difficulties to fathom, what it is exactly, that you want to accomplish.
The usual scenario, where you'd have some slightly different mechanics at work through the same interface, would imply. that you
The factory method would then have to decide, which actual implementation to invoke and store the resulting instance object in class attribute and/or return them to caller.
Any program using this construction, would only know the interface, or at most the master-class, nevertheless all implementation would be globally with "create private"
Serialization is no reason for local implementation. It will work with this as well.
With your concept of local classes, the receiving program could never know, which methods(arguments) or attributes to work. I really don't see, why anyone would want to go that way.
Best regards - Jörg
‎2014 Jul 01 8:37 AM
Hello Egor,
I am still not clear with your requirement, I am sorry friend. Please correct me if I am wrong anywhere below.
you are trying to create class factory which is having around 50 class definitions in it.
whenever you need any one object reference of those 50, you will call the factory method to get the object reference.
is it correct Egor ?
Thanks,
Bhaskar
‎2014 Jul 01 8:42 AM
Yes, you're right, but i cannot find any possibility to do that.
‎2014 Jul 01 8:55 AM
Hi Egor,
Ok that's great, I wanted to know further about your requirement.
as you mentioned you need to access 50 classes through the class factory, are those 50 classes are having different functionalities with them ?
Lets suppose they are different and each class is having different method functionalities associated with it, then with our defining them individually how do we make them work ?
please correct if I am getting deviated from your requirement.
Thanks,
Bhaskar
‎2014 Jul 01 9:13 AM
I planed create internal class through factory, change some attributes, add it to container class, which will hold all instances and then serialize this container in xml with all added classes and according to their attributes.
‎2014 Jul 01 8:52 AM
Hi Egor,
Class zcl_factory.
Public section.
TYPES: t_point TYPE REF TO LOCAL CLASS lcl_point.
Egor Titov wrote:
Class zcl_factory.
Public section.
TYPES: t_point TYPE REF TO LOCAL CLASS
i think , we can not refer local class reference to to global class variable.
‎2014 Jul 01 9:02 AM
Hello Egor,
The visibility of a local class is restricted to the program where it is defined.
Class of an ABAP program that can be viewed and used statically from the ABAP program only. Local classes can be created in all program types, with the exception of interface pools and type groups.
Ref - ABAP Keyword Documentation.
Btw i am not sure what do you mean by this -
Create everything in public will takes a lot of time, and not so beatiful
From my experience i can say that it'S far more easy to create & maintain a global class than a local class(via SE80). But if you are using Eclipse may be there's not much difference.
BR,
Suhas
‎2014 Jul 01 9:21 AM
Thank you for reply, but it very strange why it is possible to create public internal type in class, but not public internal class-type in class(
‎2014 Jul 01 9:44 AM
Egor Titov wrote:
Thank you for reply, but it very strange why it is possible to create public internal type in class, but not public internal class-type in class
What do you mean by this? Local class types are not part of the Public section of the class, so there is no straightforward way of accessing them from outside. (Read - ABAP Keyword Documentation).
Further you can see that local classes, macros are all kept in separate includes. You can use the menu function GoTo to check them out -
When you try to access the local definitions/implementations you'll get a popup telling you how these elements are separated from each other.
I use local classes very rarely and mostly for modularization purposes (as helper classes). And certainly if i had your requirement i would not think of creating local classes.
BR,
Suhas
‎2014 Jul 01 1:59 PM
Hi Egor,
can you point out, wehre in your opinion is the added value for use of local classes in your scenario?
Actually, i have some difficulties to fathom, what it is exactly, that you want to accomplish.
The usual scenario, where you'd have some slightly different mechanics at work through the same interface, would imply. that you
The factory method would then have to decide, which actual implementation to invoke and store the resulting instance object in class attribute and/or return them to caller.
Any program using this construction, would only know the interface, or at most the master-class, nevertheless all implementation would be globally with "create private"
Serialization is no reason for local implementation. It will work with this as well.
With your concept of local classes, the receiving program could never know, which methods(arguments) or attributes to work. I really don't see, why anyone would want to go that way.
Best regards - Jörg
‎2014 Jul 01 4:43 PM
Thank you for reply.
Now I realize I chose a wrong way.
I had a more than 50 different classes, and i didn't want to make them global - from my point of view, it would take more time then just write all of them in local class include, another reason - all this classes has very short time of life, in all cases they all should be created in one method and than destroyed at the end of this method(it is just a helpful classes). So I didn't see reasons to make them global.
‎2014 Jul 01 5:15 PM
Hi,
See if this desigh is what you need ?
ABAP Objects Design Patterns - Abstract Factory - ABAP Development - SCN Wiki
Regards.