Skip to content

Commit

Permalink
add code
Browse files Browse the repository at this point in the history
  • Loading branch information
VentureQ committed Jul 12, 2021
1 parent 91c8842 commit d2b411d
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 0 deletions.
15 changes: 15 additions & 0 deletions code/Design_Pattern/装饰者模式/Decorator.java
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.");
}
}
8 changes: 8 additions & 0 deletions code/Design_Pattern/装饰者模式/Source.java
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.");
}
}
5 changes: 5 additions & 0 deletions code/Design_Pattern/装饰者模式/Sourceable.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package Design_Pattern.装饰者模式;

public interface Sourceable {
public void createComputer();
}
9 changes: 9 additions & 0 deletions code/Design_Pattern/装饰者模式/Test.java
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();
}
}

0 comments on commit d2b411d

Please sign in to comment.