Passing an instance through constructors or accessing it with statics?

Recently, I have been coding the Bukkit API, but my question is not directly related to it.

There can be one instance of the main class in the Bukkit API (it new MainClass()throws an error), so I was wondering if I should pass the main class to all my classes using the constructor, OR should I use a static method that returns the instance ( MainClass.getInstance())

I am curious which one is better (in terms of performance and practice).

+4
source share
1 answer

The best approach, in terms of practice, will be your first suggestion:

Pass the main class to all my classes using the constructor

.

( encapsulation, ), , ( , PowerMock). , .


:

,

, , , Main .

, , .

, , , . , , , .

, . .

+3

Source: https://habr.com/ru/post/1681751/


All Articles