-
Notifications
You must be signed in to change notification settings - Fork 181
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1175 from matsim-org/kaibranch-2024-10-28
ConstructorInjection
- Loading branch information
Showing
2 changed files
with
59 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
src/main/java/org/matsim/codeexamples/guicewithoutmatsim/ConstructorInjection.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ; | ||
} | ||
} | ||
} |