‎2009 Mar 22 9:26 PM
Hi All,
1. I New to abap objects and i read the help and some stuff from the forum,
l like to now more about design pattern in abap objects,
2. I saw in some abap class the use of method of GET_INSTANCE i think it's from factory pattern , what is the pros. and cons to use this method ,when i should consider to use it ?
Thanks in Advance
Nina
‎2009 Mar 23 6:45 AM
Hello Nina
A very good introduction into design patterns is the book "Head First: Design Patterns". Here you will find many good reasons why and when to use the factory pattern.
You should use the factory pattern when
- you want to prevent "direct" instantiation (i.e. using a public CONSTRUCTOR method) by the developer
- you want to hide the complexity of instantiation from the user of the class
- the instantiation creates an implementation of an interface and you want to keep control of which implementing class is returned
Regards
Uwe
‎2009 Mar 23 5:01 AM
‎2009 Mar 23 6:45 AM
Hello Nina
A very good introduction into design patterns is the book "Head First: Design Patterns". Here you will find many good reasons why and when to use the factory pattern.
You should use the factory pattern when
- you want to prevent "direct" instantiation (i.e. using a public CONSTRUCTOR method) by the developer
- you want to hide the complexity of instantiation from the user of the class
- the instantiation creates an implementation of an interface and you want to keep control of which implementing class is returned
Regards
Uwe
‎2009 Mar 23 8:55 AM
>
> Hello Nina
>
> A very good introduction into design patterns is the book "Head First: Design Patterns". Here you will find many good reasons why and when to use the factory pattern....
That's one of the essentials for me when I designing new applications. Very very useful!
‎2009 Mar 23 8:33 AM
Hi,
For most of the classes where you find GET_INSTANCE method the classes instantiation would be marked as PRIVATE.
And the get_instance method would be public and static. This is to make sure that the instantiation of the class is done by the class itself in the get_instance mehod.
This is one way of getting the singleton pattern.
Regards,
Sesh