SAP / abap-cleaner

ABAP cleaner applies 75+ cleanup rules to ABAP code at a single keystroke
Apache License 2.0
400 stars 45 forks source link

Feature request: remove CREATE PRIVATE/PUBLIC when ABSTRACT #293

Open openPhiL opened 3 months ago

openPhiL commented 3 months ago

HI @jmgrassau ,

in my understanding, an abstract class cannot be created. Therefore we don't need extra definition how it is allowed to be created.

before:

CLASS ycl_test DEFINITION
  ABSTRACT
  FINAL
  CREATE PUBLIC.

after:

CLASS ycl_test DEFINITION
  ABSTRACT
  FINAL.

What do you think? Thanks PhiL

ConjuringCoffee commented 3 months ago

This would only be relevant when the class is also FINAL, right?

(Also, relevant issue from the past: #104 )

jmgrassau commented 2 months ago

Hi PhiL,

as mentioned by ConjuringCoffee, CREATE PUBLIC would still make sense for an abstract non-final class, because this information is then inherited by its subclasses:

By contrast, for an ABSTRACT FINAL class, no constructor can be declared anywhere, so as far as I can see, you're right that CREATE {PUBLIC|PROTECTED|PRIVATE} could be removed in such a case. I could just imagine this to be a hint in the sense of "for now, we'll prevent instantiation of this class, but if we ever change our minds and remove the FINAL, we then want the class to be CREATE PUBLIC" (but that may be a bit far-fetched…)

Therefore, not entirely sure what to do with this. One argument that came up in a different place is that unfortunately, ABAP classes are by default CREATE PUBLIC (while CREATE PRIVATE would be desirable to enforce static CREATE methods with good, semantic names); therefore, you should keep CREATE PUBLIC in the code as a reminder that the class design is not yet ideal. (But admittedly, that's a different story).

Kind regards, Jörg-Michael

openPhiL commented 2 weeks ago

Let me get back to this before the thread becomes stale :)

I do agree with the need to differentiate between FINAL and non-FINAL. as in: Sometimes, the create public is needed, sometimes it can be removed as not needed. as in: Somtimes, the exporting argument in a method call is needed, sometimes it can be removed as not needed :)

So I am voting for having an option in one of the rules to remove the create public if not needed, and that is if it is a abstract final class.