
ํ์ ์๋น์ค์์ ๋ค ๊ตฌํํ๊ธฐ์๋.. ์ข,,,
ํ์ ์๋น์ค์์ ๋ค ๊ตฌํํ๊ธฐ์๋ ํ์ ์๋น์ค์ ์ญํ ์ด ๋๋ฌด ๋ง๋ค.
๋ถ๋ฆฌ ์งํ-> ์ธํฐํ์ด์ค๋ก ๋ถ๋ฆฌํ ๊น? ์ถ์ ๋ฉ์๋๋ก ๋ถ๋ฆฌํ ๊น?
๋์ ์ฐจ์ด์ ์ ๋จผ์ ๋ณด์. ๋
์ธํฐํ์ด์ค์ ์ถ์๋ฉ์๋๋ ๊ฐ์ฒด๋ฅผ ๋ง๋ค ์ ์๋์๋์ ์ฐจ์ด๊ฐ ์กด์ฌํ๊ณ ,
์ธํฐํ์ด์ค๋ ๊ฐ์ฒด๋ฅผ ๋ง๋ค์ง ๋ชปํ๊ณ , ์์ฑ์๊ฐ ์๋ค๋ ํน์ง!
์ดํ ๊ฒฐ์ ํด๋ณด์~

์คํ๋ง์ ํ์
์ด ๊ฐ์๋์๋ ์ด๋ฆ์ ๋ณด๊ณ ๊ตฌ๋ณํด ๋น์์ ๊ณจ๋ผ์ ์์กด์ฑ์ ์ฃผ์
ํ๋ค.
์ถฉ๊ฒฉ์ ์คํ๋ง์ ์ฒ์ฌ๋ค..!
ํ๋์ ํ์
์ผ๋ก ์ฌ๋ฌ๊ฐ ๊ฐ์ฒด๊ฐ ์์ผ๋ฉด ๋งค๊ฐ๋ณ์ ์ด๋ฆ์ผ๋ก ๊ตฌ๋ณํ๋ค๋ ๋ป!
ํ์ง๋ง ์ถ์ฒํ์ง ์๋๋ค.
<์ด์ : ํ์
์ผ๋ก ์คํ๋ง ๋น ์ฐพ๊ธฐ์ ์คํจํ๋ฉด, ๋งค๊ฐ๋ณ์๋ช
์ผ๋ก๋ ์ฐพ์ ์๋ ์๋ค. ํ์ง๋ง, ์ถ์ฒํ์ง ์๋๋ค. ๋ถ๋ช
ํํ๊ธฐ ๋๋ฌธ >

๊ทธ๋ ๋ค๋ฉด ์ด๋ฆ๊น์ง ๊ฐ๊ฒ ๋ง๋ค๋ฉด ์คํ๋ง์ด ๊ตฌ๋ณ์ ์ ํ ๋ชปํ๊ฒ์ฐ~?
์ญ์ ์๋ฌ ๋ฐ์!!-> ์คํ๋ง: ์ผ ๊ฐ๋ฐ์์ผ! ๋น์ด 2๊ฐ์ผ...๋ญ ๋ฃ์ด์ค์ผํด?๋ผ๋ ์ค๋ฅโ๏ธ
@Primary๋ฅผ ๋นํ์์ ๋ฌ์์คฌ๋๋


ํ์์์๋ 0์ด ๋์ค๋ค,,1์ด ๋์์ผํ๋๋ฐใ
ใ
๐น
๊ทธ๋ผ MemberPolicy ๋๋์ฒด ์ด๋ป๊ฒ ์จ์ผ ํ ๊น??


: ํด๋ผ์ด์ธํธ๊ฐ ์์ ์ด ์ด์ฉํ์ง ์๋ ๋ฉ์๋์ ์์กดํ์ง ์์์ผ ํ๋ค๋ ์์น
(์ปจ๋ฒค์
: ์ฝ์)
Marshall, JBL, Britz implements BluetoothAISpeakeMarshall: Speaker, Blutooth, AJBL: Speaker, BlutootBritz: Speaker์๋์ง ์๋์ง
[1] ๋งค๊ฐ๋ณ์๋ก ๋ฐ์์ ์ฌ์ฉํ๋ ๋ฉ์๋๋ฅผ ์ค๋ฒ๋ก๋ฉ
[2] ์์ ์ธํฐํ์ด์ค๋ฅผ ๋ง๋ค์ด์, ํ๋ค๋ฆฌ ์ ์ด์ ๋ค์ด๊ฐ ๊ตฌํ์ฒด๋ฅผ instancof + ์บ์คํ
์ ํ์ฉํ์ฌ ํ๋ค๋ฆฌ ๋ค์ ํ
package com.example.summer.isp;
interface ABInterface {
}
interface AInterface extends ABInterface{
void methodA();
}
interface BInterface extends ABInterface{
void methodB();
}
class ImplA implements AInterface{
@Override
public void methodA() {
System.out.println("implA");
}
}
class ImplB implements BInterface {
@Override
public void methodB() {
System.out.println("implB");
}
}
public class IspDemo {
public static void main(String[] args) {
ispMethod(new ImplA());
ispMethod(new ImplB());
}
public static void ispMethod(ABInterface abInterface) {
if (abInterface instanceof AInterface)
((AInterface) abInterface).methodA();
else if (abInterface instanceof BInterface)
((BInterface) abInterface).methodB();
}
}
[3] ์ ๋ค๋ฆญ ์ฌ์ฉ
package com.example.summer.isp;
interface ABInterface {
}
interface AInterface extends ABInterface{
void methodA();
}
interface BInterface extends ABInterface{
void methodB();
}
class ImplA implements AInterface{
@Override
public void methodA() {
System.out.println("implA");
}
}
class ImplB implements BInterface {
@Override
public void methodB() {
System.out.println("implB");
}
}
public class IspDemo {
public static void main(String[] args) {
GenericIsp<AInterface> genericIspA = new GenericIsp<>();
genericIspA.ispMethod(new ImplA());
GenericIsp<BInterface> genericIspB = new GenericIsp<>();
genericIspB.ispMethod(new ImplB());
}
}
class GenericIsp<T> {
public void ispMethod(T abInterface) {
if (abInterface instanceof AInterface)
((AInterface) abInterface).methodA();
else if (abInterface instanceof BInterface)
((BInterface) abInterface).methodB();
}
}
๋น๊ทผ ์๋ฌ์ ๋น๊ทผ๋ผํ ์ข์์