반응형
1. 자바 delegate Pattern
2. 코틀린 delegate pattern
틀린 곳이 있을 수 있습니다. 지적부탁드립니다.
1. 자바 delegate Pattern
package delegate2.one;
public class Main {
public static void main(String[] args) {
BBB x = new BBB("James");
x.methodHello();
x.methodBye();
}
}
interface Greet {
void methodHello();
void methodBye();
}
class AAA implements Greet {
String name = "";
AAA(String name){
this.name = name;
}
@Override
public void methodHello() {
System.out.println(name+", hello");
}
@Override
public void methodBye() {
System.out.println(name+", bye");
}
}
class BBB implements Greet {
private AAA aaa;
BBB(String name){
this.aaa = new AAA(name);
}
@Override
public void methodHello() {
aaa.methodHello();
}
@Override
public void methodBye() {
aaa.methodBye();
}
}
2. 코틀린 delegate pattern
package delegate2
class Main {
}
fun main() {
var bbb = BBB("james")
bbb.hello()
bbb.bye()
}
interface Greet{
fun hello()
fun bye()
}
class AAA(private val name:String) : Greet{
override fun hello() {
println("${name}, hello")
}
override fun bye() {
println("${name}, bye")
}
}
class BBB(private val name:String) : Greet by AAA(name){
}