Skip to content

Commit

Permalink
updating protection proxy class names
Browse files Browse the repository at this point in the history
  • Loading branch information
bethrobson committed Sep 16, 2020
1 parent 4a072f3 commit 30f4f5a
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import java.util.*;

public class MatchMakingTestDrive {
HashMap<String, PersonBean> datingDB = new HashMap<String, PersonBean>();
HashMap<String, Person> datingDB = new HashMap<String, Person>();

public static void main(String[] args) {
MatchMakingTestDrive test = new MatchMakingTestDrive();
Expand All @@ -16,8 +16,8 @@ public MatchMakingTestDrive() {
}

public void drive() {
PersonBean joe = getPersonFromDatabase("Joe Javabean");
PersonBean ownerProxy = getOwnerProxy(joe);
Person joe = getPersonFromDatabase("Joe Javabean");
Person ownerProxy = getOwnerProxy(joe);
System.out.println("Name is " + ownerProxy.getName());
ownerProxy.setInterests("bowling, Go");
System.out.println("Interests set from owner proxy");
Expand All @@ -28,7 +28,7 @@ public void drive() {
}
System.out.println("Rating is " + ownerProxy.getGeekRating());

PersonBean nonOwnerProxy = getNonOwnerProxy(joe);
Person nonOwnerProxy = getNonOwnerProxy(joe);
System.out.println("Name is " + nonOwnerProxy.getName());
try {
nonOwnerProxy.setInterests("bowling, Go");
Expand All @@ -40,34 +40,34 @@ public void drive() {
System.out.println("Rating is " + nonOwnerProxy.getGeekRating());
}

PersonBean getOwnerProxy(PersonBean person) {
Person getOwnerProxy(Person person) {

return (PersonBean) Proxy.newProxyInstance(
return (Person) Proxy.newProxyInstance(
person.getClass().getClassLoader(),
person.getClass().getInterfaces(),
new OwnerInvocationHandler(person));
}

PersonBean getNonOwnerProxy(PersonBean person) {
Person getNonOwnerProxy(Person person) {

return (PersonBean) Proxy.newProxyInstance(
return (Person) Proxy.newProxyInstance(
person.getClass().getClassLoader(),
person.getClass().getInterfaces(),
new NonOwnerInvocationHandler(person));
}

PersonBean getPersonFromDatabase(String name) {
return (PersonBean)datingDB.get(name);
Person getPersonFromDatabase(String name) {
return (Person)datingDB.get(name);
}

void initializeDatabase() {
PersonBean joe = new PersonBeanImpl();
Person joe = new PersonImpl();
joe.setName("Joe Javabean");
joe.setInterests("cars, computers, music");
joe.setGeekRating(7);
datingDB.put(joe.getName(), joe);

PersonBean kelly = new PersonBeanImpl();
Person kelly = new PersonImpl();
kelly.setName("Kelly Klosure");
kelly.setInterests("ebay, movies, music");
kelly.setGeekRating(6);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
import java.lang.reflect.*;

public class NonOwnerInvocationHandler implements InvocationHandler {
PersonBean person;
Person person;

public NonOwnerInvocationHandler(PersonBean person) {
public NonOwnerInvocationHandler(Person person) {
this.person = person;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
import java.lang.reflect.*;

public class OwnerInvocationHandler implements InvocationHandler {
PersonBean person;
Person person;

public OwnerInvocationHandler(PersonBean person) {
public OwnerInvocationHandler(Person person) {
this.person = person;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package headfirst.designpatterns.proxy.javaproxy;

public interface PersonBean {
public interface Person {

String getName();
String getGender();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package headfirst.designpatterns.proxy.javaproxy;

public class PersonBeanImpl implements PersonBean {
public class PersonImpl implements Person {
String name;
String gender;
String interests;
Expand Down

0 comments on commit 30f4f5a

Please sign in to comment.