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

Class with only static methodes?

Former Member
0 Likes
981

Hi,

is there a disadvantage if i create a class with only static methodes. I don't need to create object, just use static methodes.

I want this class because we are using same select statements several times in different methodes.

tnx. Adibo

1 ACCEPTED SOLUTION
Read only

naimesh_patel
Active Contributor
0 Likes
926

Adibo A wrote:

is there a disadvantage if i create a class with only static methodes. I don't need to create object, just use static methodes.

There is not disadvantage. If you are storing something in STATIC attributes, than you need to pay extra attention while clearing them. Otherwise, this method would be simply an Utility method which accepts the input and gives back the output.

I want this class because we are using same select statements several times in different methodes.

Are these methods being called  in the same LUW or Session with Same input parameter with same expected Output? If yes, than you should consider Singleton DP.

Regards,
Naimesh Patel

6 REPLIES 6
Read only

UweFetzer_se38
Active Contributor
0 Likes
926

Hi Adibo,

is there a disadvantage if i create a class with only static methodes. I don't need to create object, just use static methodes.

If you really don't need to store results for further calls, IMO there are no disadvantages.

I want this class because we are using same select statements several times in different methodes.

I don't really understand your needs, but I thinks this is not important for my 1st answer

Best regards

Read only

Kiran_Valluru
Active Contributor
0 Likes
926

Hi,

I want this class because we are using same select statements several times indifferent methodes.

For this, you can create a class using singleton design pattern, and create static attributes( table types) to store date from DB and you can access those attributes.

Hope this helps u.,

Thanks & Regards,

Kiran.

Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
926

kiran kumar Reddy wrote:

For this, you can create a class using singleton design pattern, and create static attributes( table types) to store date from DB and you can access those attributes.

Why?

Singleton DP is implemented if you want to use the same instance of a class through out your application. If i understand correctly the OP doesn't need to work with an instance of the class, so why Singleton, please enlighten us?

Read only

0 Likes
926

Hi Suhas,

Sorry for my late reply. As the OP asked,

I want this class because we are using same select statements several times in different methodes.

What I feel was, he could have create a class using singleton DP, and for the first time, fetch the data from DB and store in the attributes of that instance. Now when he wants the data again, he can check whether the instance is bound or not. if it is bound, he can avoid hitting DB!

Correct me if you feel it is wrong.

Regards,

Kiran.

Read only

naimesh_patel
Active Contributor
0 Likes
927

Adibo A wrote:

is there a disadvantage if i create a class with only static methodes. I don't need to create object, just use static methodes.

There is not disadvantage. If you are storing something in STATIC attributes, than you need to pay extra attention while clearing them. Otherwise, this method would be simply an Utility method which accepts the input and gives back the output.

I want this class because we are using same select statements several times in different methodes.

Are these methods being called  in the same LUW or Session with Same input parameter with same expected Output? If yes, than you should consider Singleton DP.

Regards,
Naimesh Patel

Read only

Former Member
0 Likes
926

Hi,

Tnx all, for the answers!!

@Patel, method could be called in the same LUW but I don expect the same output.

I'am just using static methods to reduce some code and to prevent writing same select statement over and over again..

See my code:

zCL_STATIC_METHODS

GET_ZAKENPARTNER_SOORTStatic MethodPublic
Get Zakenpartner Soort'
I_PARTNERImportingTypeBU_PARTNER
Nummer zakenpartner
E_TEXTExportingTypeBU_TEXT40
Omschrijving

METHOD get_zakenpartner_soort.

   SELECT SINGLE tb004t~text40 INTO e_text

   FROM but000

   INNER JOIN tb004t ON but000~bpkind EQ tb004t~bpkind  "#EC CI_BUFFJOIN

   WHERE but000~partner EQ i_partner.

ENDMETHOD.

And i call it like this:

REPORT  z_static_call.

DATA: lv_text TYPE bu_text40.

zcl_static_methods=>get_zakenpartner_soort(

                                                     EXPORTING i_partner = '0010000278'

                                                     IMPORTING e_text    = lv_text ).

BREAK-POINT.

As simple as that.