What’s the advantage of having public static inner classes of an interface/class?

I think this is reasoned by aggregation, maybe they’re also not worth it to create a top level class. I do this sometimes if something is to small to create a package (to separate them from others) but the corresponding classes should only used within the context of the top level class. In my opinion this is a design decision.

The decorator pattern may be a nice example, they can be applied on the top-level class but are maybe so simple they’re not worth it to be also top-level. You can easily show the ownership by using them as inner classes.

That’s not that visible at first glance with packages. You directly see the dependent class/interface.

Further it’s possible to access the private fields of a class, this could be useful and is more fine-grained than the package private scope.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)