0
@AllArgsConstructor(onConstructor = @__({ @Inject }))
public class TransactionManager {

    private final TransactionHelper tnxHelper;

    public void createTransactions(List<Details> details) {
        tnxHelper.createTransactions(details); 
    }
}

@AllArgsConstructor(onConstructor = @__({ @Inject }))
public class TransactionHelper {

    private final A a;    
    private final B b;

    public void createTransactions(List<Details> details) {
        //Some logic
    }
}

So in the above code, I want TransactionManager to be the main class and every interactions related to Transaction should go via it, like createTransactions.

So how can i make TransactionHelper as hidden? So that no one can use this class apart from TransactionManager?

Also is there any way to only make createTransactions in TransactionHelper as hidden, rather than hiding the whole class.

Thank you in advance!!

Anamika Patel
  • 135
  • 2
  • 6
  • https://stackoverflow.com/questions/215497/what-is-the-difference-between-public-protected-package-private-and-private-in – fantaghirocco Jan 12 '22 at 10:33

1 Answers1

1

Is the usage of Nested classes resolve your problem ? https://docs.oracle.com/javase/tutorial/java/javaOO/nested.html

class TransactionManager {
  // you cannot use the class TransactionHelper outside the TransactionManagerClass 
  // you need an instance of TransactionManager to have an instance of TransactionHelper 
  // so within static methods here you cant use it directly
  private class TransactionHelper {
  }

  void dooo() {
    TransactionHelper t = new TransactionHelper();
  }
}
Oussama ZAGHDOUD
  • 1,767
  • 5
  • 15