-
Notifications
You must be signed in to change notification settings - Fork 271
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
410 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
design-patterns-basic/src/main/java/org/landy/adapter/classadapter/PS2ToUsberAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package org.landy.adapter.classadapter; | ||
|
||
import org.landy.adapter.domain.PS2; | ||
import org.landy.adapter.domain.Usber; | ||
|
||
/** | ||
* @author: landy | ||
* @date: 2019/5/19 11:37 | ||
* @description: | ||
*/ | ||
public class PS2ToUsberAdapter extends Usber implements PS2 { | ||
@Override | ||
public boolean isPs2() { | ||
System.out.println("PS2接口转化为了USB接口"); | ||
return isUsb(); | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
design-patterns-basic/src/main/java/org/landy/adapter/classadapter/Test.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package org.landy.adapter.classadapter; | ||
|
||
import org.landy.adapter.domain.PS2; | ||
|
||
/** | ||
* @author: landy | ||
* @date: 2019/5/19 11:39 | ||
* @description: | ||
*/ | ||
public class Test { | ||
|
||
public static void main(String[] args) { | ||
PS2 p = new PS2ToUsberAdapter(); | ||
p.isPs2(); | ||
} | ||
|
||
} |
12 changes: 12 additions & 0 deletions
12
design-patterns-basic/src/main/java/org/landy/adapter/domain/PS2.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package org.landy.adapter.domain; | ||
|
||
/** | ||
* @author: landy | ||
* @date: 2019/5/19 11:36 | ||
* @description: | ||
*/ | ||
public interface PS2 { | ||
|
||
boolean isPs2(); | ||
|
||
} |
12 changes: 12 additions & 0 deletions
12
design-patterns-basic/src/main/java/org/landy/adapter/domain/USB.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package org.landy.adapter.domain; | ||
|
||
/** | ||
* @author: landy | ||
* @date: 2019/5/19 11:35 | ||
* @description: | ||
*/ | ||
public interface USB { | ||
|
||
boolean isUsb(); | ||
|
||
} |
16 changes: 16 additions & 0 deletions
16
design-patterns-basic/src/main/java/org/landy/adapter/domain/Usber.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package org.landy.adapter.domain; | ||
|
||
import org.landy.adapter.domain.USB; | ||
|
||
/** | ||
* @author: landy | ||
* @date: 2019/5/19 11:36 | ||
* @description: | ||
*/ | ||
public class Usber implements USB { | ||
@Override | ||
public boolean isUsb() { | ||
System.out.println("这是一个USB接口"); | ||
return true; | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
design-patterns-basic/src/main/java/org/landy/adapter/interfaceadapter/Test.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package org.landy.adapter.interfaceadapter; | ||
|
||
/** | ||
* @author: landy | ||
* @date: 2019/5/19 12:07 | ||
* @description: | ||
*/ | ||
public class Test { | ||
|
||
public static void main(String[] args) { | ||
// 比如java.awt.event.MouseAdapter类就是一个接口适配器,他实现的都是空方法, | ||
// 由具体的子类选择性的挑选需要的方法进行相应的实现 | ||
} | ||
|
||
} |
24 changes: 24 additions & 0 deletions
24
design-patterns-basic/src/main/java/org/landy/adapter/objectadapter/PS2ToUsberAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package org.landy.adapter.objectadapter; | ||
|
||
import org.landy.adapter.domain.PS2; | ||
import org.landy.adapter.domain.USB; | ||
|
||
/** | ||
* @author: landy | ||
* @date: 2019/5/19 11:52 | ||
* @description: | ||
*/ | ||
public class PS2ToUsberAdapter implements PS2 { | ||
|
||
private USB usb; | ||
|
||
public PS2ToUsberAdapter(USB usb) { | ||
this.usb = usb; | ||
} | ||
|
||
@Override | ||
public boolean isPs2() { | ||
System.out.println("PS2接口转化为了USB接口"); | ||
return usb.isUsb(); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
design-patterns-basic/src/main/java/org/landy/adapter/objectadapter/Test.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package org.landy.adapter.objectadapter; | ||
|
||
import org.landy.adapter.domain.PS2; | ||
import org.landy.adapter.domain.Usber; | ||
|
||
/** | ||
* @author: landy | ||
* @date: 2019/5/19 11:55 | ||
* @description: | ||
*/ | ||
public class Test { | ||
|
||
public static void main(String[] args) { | ||
PS2 p = new PS2ToUsberAdapter(new Usber()); | ||
p.isPs2(); | ||
} | ||
|
||
} |
14 changes: 14 additions & 0 deletions
14
design-patterns-business/src/test/java/defaultmethod/Addition.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package defaultmethod; | ||
|
||
/** | ||
* @author: landy | ||
* @date: 2019/5/19 09:29 | ||
* @description: | ||
*/ | ||
public interface Addition { | ||
|
||
default int add(int a, int b) { | ||
return a + b; | ||
} | ||
|
||
} |
22 changes: 22 additions & 0 deletions
22
design-patterns-business/src/test/java/defaultmethod/AdditionImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package defaultmethod; | ||
|
||
/** | ||
* @author: landy | ||
* @date: 2019/5/19 09:30 | ||
* @description: | ||
*/ | ||
public class AdditionImpl implements Addition { | ||
|
||
/** | ||
* 接口默认方法的 ”类优先” 原则:若一个接口中定义了一个默认方法, | ||
* 而另外一个父类或接口中又定义了一个同名的方法时选择父类中的方法: | ||
* 如果一个父类提供了具体的实现,那么接口中具有相同名称和参数的默认方法会被忽略。 | ||
* @param a | ||
* @param b | ||
* @return | ||
*/ | ||
@Override | ||
public int add(int a, int b) { | ||
return a + b + 10; | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
design-patterns-business/src/test/java/defaultmethod/AdditionImpl2.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package defaultmethod; | ||
|
||
/** | ||
* @author: landy | ||
* @date: 2019/5/19 09:33 | ||
* @description: | ||
*/ | ||
public class AdditionImpl2 implements Addition { | ||
} |
Oops, something went wrong.