Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Adapter_Ilalov/Android.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export interface Android {
//method that belongs only to Android
useMicroUSB();
}
9 changes: 9 additions & 0 deletions Adapter_Ilalov/AndroidImpl.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import {Android} from "./Android";


export class AndroidImpl implements Android {
//realisation method
useMicroUSB() {
console.log("Using micro USB")
}
}
4 changes: 4 additions & 0 deletions Adapter_Ilalov/IPhone.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export interface IPhone {
//method that belongs only to iPhone
useLightning();
}
17 changes: 17 additions & 0 deletions Adapter_Ilalov/LightningToMicroUSBAdapter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import {Android} from "./Android";
import {IPhone} from "./IPhone";

export class LightningToMicroUSBAdapter implements Android {
// Class iPhoneImpl does not have a useMicroUSB, so we can create an adapter
iphoneDevice: IPhone;

constructor(iphone: IPhone) {
this.iphoneDevice = iphone;
}

public useMicroUSB() {
console.log("Want to use micro USB, converting to Lightning")
//calls the method useLightning instead
this.iphoneDevice.useLightning();
}
}
12 changes: 12 additions & 0 deletions Adapter_Ilalov/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Adapter Pattern
# The adapter pattern allows you to make different classes with different interfaces work together, without changing their source code.
## Execution

* **Step 1**: Run the typescript file with the following command. This will create a javascript file from typescript automatically with the same name.
```bash
tsc main.ts
```
* **Step 2**: Now run the javascript file
```bash
node main.js
```
8 changes: 8 additions & 0 deletions Adapter_Ilalov/iPhoneImpl.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import {IPhone} from "./IPhone";

export class iPhoneImpl implements IPhone {
//realisation method
useLightning() {
console.log("Using lightning port")
}
}
8 changes: 8 additions & 0 deletions Adapter_Ilalov/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import {iPhoneImpl} from "./iPhoneImpl";
import {LightningToMicroUSBAdapter} from "./LightningToMicroUSBAdapter";

//functional test
let iphone7 = new iPhoneImpl();
let chargeAdapter = new LightningToMicroUSBAdapter(iphone7);

chargeAdapter.useMicroUSB()