Created
September 13, 2012 05:11
-
-
Save gakuzzzz/3712015 to your computer and use it in GitHub Desktop.
オブジェクト指向エクササイズのアクセサ禁止
This file contains hidden or 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
// これはNG | |
public class User { | |
private String name; | |
private int age; | |
public User(String name, int age) { | |
this.name = name; | |
this.age = age; | |
} | |
public String getName() {return name;} | |
public int getAge() {return age;} | |
} | |
public class UserFinder { | |
public static void main(String[] args) { | |
User user = UserRepository.findByName(args[0]); | |
System.out.format("User(name=%s, age=%d)\n", user.getName(), user.getAge()); | |
} | |
} |
This file contains hidden or 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
// こういう風にしろ | |
public class User { | |
private String name; | |
private int age; | |
public User(String name, int age) { | |
this.name = name; | |
this.age = age; | |
} | |
public void display(PrintStream out) { | |
out.format("User(name=%s, age=%d)\n", user.getName(), user.getAge()); | |
} | |
} | |
public class UserFinder { | |
public static void main(String[] args) { | |
User user = UserRepository.findByName(args[0]); | |
user.display(System.out) | |
} | |
} |
test
testtest
test
test
もっかいテスト
test
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
てst