forked from slgobinath/Java-Helps-Java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathComputer.java
More file actions
35 lines (30 loc) · 751 Bytes
/
Computer.java
File metadata and controls
35 lines (30 loc) · 751 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/**
* In real world USB port is a point of interaction - Interface.
* This code simulates the real world scenario using interface.
*
* @author L.Gobinath
*/
public class Computer {
public static void main(String[] args) {
Computer comp = new Computer();
}
public void connect(USB usb) {
usb.send(new byte[] {1}); // Send some data
byte[] data = usb.receive(); // Receive some data
// do something here
}
}
interface USB {
void send(byte[] data);
byte[] receive();
}
class Mouse implements USB {
@Override
public void send(byte[] data) {
System.out.println("Connected");
}
@Override
public byte[] receive() {
return new byte[] {120, 87};
}
}