Skip to content

Commit c07e771

Browse files
committed
Before code for Adapter design pattern
- iphone ear plug example
1 parent 2cd8809 commit c07e771

4 files changed

Lines changed: 61 additions & 2 deletions

File tree

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,29 @@
11
package 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
*/
911
public 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
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
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+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
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+
}

0 commit comments

Comments
 (0)