diff --git a/code-manipulation/dynamic-proxy/pom.xml b/code-manipulation/dynamic-proxy/pom.xml new file mode 100644 index 00000000..620c0c23 --- /dev/null +++ b/code-manipulation/dynamic-proxy/pom.xml @@ -0,0 +1,30 @@ + + + + 4.0.0 + + org.example + dynamic-proxy + 1.0-SNAPSHOT + + dynamic-proxy + + http://www.example.com + + + UTF-8 + 11 + 11 + + + + + junit + junit + 4.11 + test + + + + diff --git a/code-manipulation/dynamic-proxy/src/main/java/org/example/proxy/Book.java b/code-manipulation/dynamic-proxy/src/main/java/org/example/proxy/Book.java new file mode 100644 index 00000000..610c4a01 --- /dev/null +++ b/code-manipulation/dynamic-proxy/src/main/java/org/example/proxy/Book.java @@ -0,0 +1,24 @@ +package org.example.proxy; + +public class Book { + + private Integer id; + + private String title; + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } +} diff --git a/code-manipulation/dynamic-proxy/src/main/java/org/example/proxy/BookService.java b/code-manipulation/dynamic-proxy/src/main/java/org/example/proxy/BookService.java new file mode 100644 index 00000000..540fe94e --- /dev/null +++ b/code-manipulation/dynamic-proxy/src/main/java/org/example/proxy/BookService.java @@ -0,0 +1,6 @@ +package org.example.proxy; + +public interface BookService { + + void rent(Book book); +} diff --git a/code-manipulation/dynamic-proxy/src/main/java/org/example/proxy/BookServiceProxy.java b/code-manipulation/dynamic-proxy/src/main/java/org/example/proxy/BookServiceProxy.java new file mode 100644 index 00000000..89f04f7e --- /dev/null +++ b/code-manipulation/dynamic-proxy/src/main/java/org/example/proxy/BookServiceProxy.java @@ -0,0 +1,17 @@ +package org.example.proxy; + +public class BookServiceProxy implements BookService { + + BookService bookService; + + public BookServiceProxy(BookService bookService) { + this.bookService = bookService; + } + + @Override + public void rent(Book book) { + System.out.println("로깅!!"); + bookService.rent(book); + System.out.println("다른기능!!"); + } +} diff --git a/code-manipulation/dynamic-proxy/src/main/java/org/example/proxy/DefaultBookService.java b/code-manipulation/dynamic-proxy/src/main/java/org/example/proxy/DefaultBookService.java new file mode 100644 index 00000000..57b95acd --- /dev/null +++ b/code-manipulation/dynamic-proxy/src/main/java/org/example/proxy/DefaultBookService.java @@ -0,0 +1,9 @@ +package org.example.proxy; + +public class DefaultBookService implements BookService{ + + @Override + public void rent(Book book) { + System.out.println("rent: " + book.getTitle()); + } +} diff --git a/code-manipulation/dynamic-proxy/src/test/java/org/example/proxy/BookServiceTest.java b/code-manipulation/dynamic-proxy/src/test/java/org/example/proxy/BookServiceTest.java new file mode 100644 index 00000000..a59dc5b2 --- /dev/null +++ b/code-manipulation/dynamic-proxy/src/test/java/org/example/proxy/BookServiceTest.java @@ -0,0 +1,17 @@ +package org.example.proxy; + +import org.junit.Test; + +public class BookServiceTest { + + BookService bookService = new BookServiceProxy(new DefaultBookService()); + + @Test + public void proxy() { + + Book book = new Book(); + book.setTitle("spring"); + + bookService.rent(book); + } +} \ No newline at end of file