File tree Expand file tree Collapse file tree
pattern/src/com/premaseem Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11package com .premaseem ;
22
3+ import com .premaseem .phones .GooglePhone ;
4+ import com .premaseem .phones .IPhone ;
5+
36/*
47@author: Aseem Jain
58@title: Design Patterns with Java 9
69@link: https://premaseem.wordpress.com/category/computers/design-patterns/
7- @copyright: 2018 Packt Publication
810*/
911public class Client {
1012 public static void main (String [] args ) {
11- System .out .println ("Singleton cook example " );
13+ System .out .println ("Adapter Design Pattern Example " );
14+
15+ // Created instances of devices
16+ IPhone iPhone = new IPhone ();
17+ GooglePhone googlePhone = new GooglePhone ();
18+ EarPlug earPlug = new EarPlug ();
19+
20+ // Ear plug is able to take iPhone sound signal
21+ String soundSignal = iPhone .getSoundOutput ();
22+ earPlug .takeSoundInput (soundSignal );
23+
24+ // Ear plug is not able to take google phone sound signal
25+ Integer soundSignals = googlePhone .getSoundOutput ();
26+ earPlug .takeSoundInput (soundSignals );
27+
1228 }
1329}
Original file line number Diff line number Diff line change 1+ package com .premaseem ;
2+
3+ /*
4+ @author: Aseem Jain
5+ @title: Design Patterns with Java 9
6+ @link: https://premaseem.wordpress.com/category/computers/design-patterns/
7+ */
8+ public class EarPlug {
9+
10+ public void takeSoundInput (String inputSignal ){
11+ System .out .println ("playing input signal" );
12+ System .out .println (inputSignal );
13+ }
14+
15+ }
Original file line number Diff line number Diff line change 1+ package com .premaseem .phones ;
2+
3+ /*
4+ @author: Aseem Jain
5+ @title: Design Patterns with Java 9
6+ @link: https://premaseem.wordpress.com/category/computers/design-patterns/
7+ */
8+ public class GooglePhone {
9+
10+ public Integer getSoundOutput (){
11+
12+ return 1001010101 ;
13+ }
14+ }
Original file line number Diff line number Diff line change 1+ package com .premaseem .phones ;
2+
3+ /*
4+ @author: Aseem Jain
5+ @title: Design Patterns with Java 9
6+ @link: https://premaseem.wordpress.com/category/computers/design-patterns/
7+ */
8+ public class IPhone {
9+
10+ public String getSoundOutput (){
11+
12+ return "1001010101" ;
13+ }
14+ }
You can’t perform that action at this time.
0 commit comments