-
Notifications
You must be signed in to change notification settings - Fork 0
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
4 changed files
with
37 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package Design_Pattern.装饰者模式; | ||
|
||
public class Decorator implements Sourceable{ | ||
private Sourceable source; | ||
|
||
public Decorator(Sourceable source) { | ||
this.source = source; | ||
} | ||
|
||
@Override | ||
public void createComputer() { | ||
source.createComputer(); | ||
System.out.println("make system."); | ||
} | ||
} |
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,8 @@ | ||
package Design_Pattern.装饰者模式; | ||
|
||
public class Source implements Sourceable{ | ||
@Override | ||
public void createComputer() { | ||
System.out.println("create computer by Source."); | ||
} | ||
} |
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,5 @@ | ||
package Design_Pattern.装饰者模式; | ||
|
||
public interface Sourceable { | ||
public void createComputer(); | ||
} |
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 Design_Pattern.装饰者模式; | ||
|
||
public class Test { | ||
public static void main(String[] args) { | ||
Sourceable source=new Source(); | ||
Sourceable obj=new Decorator(source); | ||
obj.createComputer(); | ||
} | ||
} |