File tree Expand file tree Collapse file tree 5 files changed +86
-0
lines changed Expand file tree Collapse file tree 5 files changed +86
-0
lines changed Original file line number Diff line number Diff line change
1
+ package sdp .adapter ;
2
+
3
+ /**
4
+ *
5
+ * @author rafiul islam
6
+ */
7
+ public interface Driver {
8
+ public void engine (String support );
9
+ }
Original file line number Diff line number Diff line change
1
+ package sdp .adapter ;
2
+
3
+ /**
4
+ *
5
+ * @author rafiul islam
6
+ */
7
+ public class Main {
8
+ public static void main (String [] args ) {
9
+ Windows pc = new Windows ();
10
+ pc .execute ("exe" );
11
+ pc .execute ("py" );
12
+
13
+ Python python = new Python ();
14
+ pc .install ("py" , python );
15
+ pc .execute ("py" );
16
+ }
17
+ }
Original file line number Diff line number Diff line change
1
+ package sdp .adapter ;
2
+
3
+ /**
4
+ *
5
+ * @author rafiul islam
6
+ */
7
+ public interface OS {
8
+ public void install (String type , Driver driver );
9
+ public void execute (String type );
10
+ }
Original file line number Diff line number Diff line change
1
+ package sdp .adapter ;
2
+
3
+ /**
4
+ *
5
+ * @author rafiul islam
6
+ */
7
+ public class Python implements Driver {
8
+
9
+ @ Override
10
+ public void engine (String type ){
11
+ System .out .println ("Python interpreter engine: " +type );
12
+ }
13
+ }
Original file line number Diff line number Diff line change
1
+ package sdp .adapter ;
2
+
3
+ import java .util .HashMap ;
4
+
5
+ /**
6
+ *
7
+ * @author rafiul islam
8
+ */
9
+ public class Windows implements OS {
10
+ private HashMap installedDrivers ;
11
+
12
+ public Windows (){
13
+ installedDrivers = new HashMap ();
14
+ }
15
+
16
+ @ Override
17
+ public void install (String type , Driver driver ){
18
+ installedDrivers .put (type , driver );
19
+ }
20
+
21
+ @ Override
22
+ public void execute (String type ){
23
+ type = type .toLowerCase ();
24
+ if (type == "exe" || type == "msi" ){
25
+ System .out .println ("Windows default execution engine: " +type );
26
+ }
27
+ else {
28
+ Driver driver = (Driver )installedDrivers .get (type );
29
+ if (driver == null ){
30
+ System .out .println ("No supported driver found" );
31
+ }
32
+ else {
33
+ driver .engine (type );
34
+ }
35
+ }
36
+ }
37
+ }
You can’t perform that action at this time.
0 commit comments