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

Get instance method and design pattern

Former Member
0 Likes
4,503

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

1 ACCEPTED SOLUTION
Read only

uwe_schieferstein
Active Contributor
0 Likes
2,151

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

4 REPLIES 4
Read only

Former Member
0 Likes
2,151

This message was moderated.

Read only

uwe_schieferstein
Active Contributor
0 Likes
2,152

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

Read only

0 Likes
2,151

>

> 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!

Read only

seshatalpasai_madala
Product and Topic Expert
Product and Topic Expert
0 Likes
2,151

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