Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ConstructorInjection #1175

Merged
merged 1 commit into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public static void main(String[] args) {

config.checkConsistency();

ControlerUtils.checkConfigConsistencyAndWriteToLog(config, "test");
ControlerUtils.checkConfigConsistencyAndWriteToLog(config, "test" );

}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package org.matsim.codeexamples.guicewithoutmatsim;

import com.google.inject.Inject;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

class ConstructorInjection{

private static final Logger log = LogManager.getLogger( org.matsim.codeexamples.guicewithoutmatsim.PartOne.class ) ;

public static void main(String[] args){
Helper helper = new MyHelper1();
Simulation simulation = new MySimulation1( helper );
simulation.run();
}

interface Simulation {
void run() ;
}

interface Helper {
Object getAccessToSomething() ;
}

static class MySimulation1 implements Simulation{
private final Helper helper;
MySimulation1( Helper helper ) {
this.helper = helper;
}
@Override public void run() {
log.info( "called MySimulation1 run method") ;
helper.getAccessToSomething() ;
}
}
static class MySimulation2 implements Simulation{
private final Helper helper;
MySimulation2( Helper helper ) {
this.helper = helper;
}
@Override public void run() {
log.info( "called MySimulation2 run method") ;
helper.getAccessToSomething() ;
}
}

static class MyHelper1 implements Helper{
@Override public Object getAccessToSomething(){
log.info( "called MyHelper1 getAccess... method") ;
return null ;
}
}
static class MyHelper2 implements Helper{
@Override public Object getAccessToSomething(){
log.info( "called MyHelper2 getAccess... method") ;
return null ;
}
}
}
Loading