Skip to content

Commit

Permalink
Merge pull request #1175 from matsim-org/kaibranch-2024-10-28
Browse files Browse the repository at this point in the history
ConstructorInjection
  • Loading branch information
kainagel authored Oct 28, 2024
2 parents 5de30b6 + 1d62c86 commit 526bc35
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 1 deletion.
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 ;
}
}
}

0 comments on commit 526bc35

Please sign in to comment.