Search
moon
sun
๐Ÿ“

ISP : The Interface Segregation Principle

Category
as S/W ์—”์ง€๋‹ˆ์–ด
Tags
S/W Engineering
Architecture
Study Note
ISP
SOLID
Created time
2009/04/17

Definition

โ€ข
ํด๋ผ์ด์–ธํŠธ ์ฝ”๋“œ๊ฐ€ ์ž์‹ ์ด ์‚ฌ์šฉํ•˜์ง€ ์•Š๋Š” method์— ์˜์กดํ•˜๋„๋ก ๊ฐ•์ œ๋˜์–ด์„œ๋Š” ์•„๋‹ˆ๋จ
โ€ข
์œ„ ์‚ฌํ•ญ์„ ์œ„ํ•ด ๋‹ค์ˆ˜์˜ interface๋กœ ๋ถ„๋ฆฌ ๋ฐ ํ•ด๋‹น interface์— ํด๋ผ์ด์–ธํŠธ ์ฝ”๋“œ๊ฐ€ ์˜์กดํ•˜๋„๋ก ํ•จ. ์ด๋กœ์„œ ์„œ๋กœ ๋‹ค๋ฅธ ํด๋ผ์ด์–ธํŠธ ์ฝ”๋“œ๊ฐ€ ์„œ๋กœ์— ๋Œ€ํ•ด ๋…๋ฆฝ์ ์ด ๋˜๋„๋ก ํ•จ.

ISP violated sample

public interface Modem { // connection responsibility public void Dial(string pno); public void Hangup(); // data channel responsibility public void Send(char c); public char Recv(); }
C#
๋ณต์‚ฌ

ํŠน์ง•

โ€ข
Connection๊ณผ data channel์ด๋ž€ ๋‘ ๊ฐœ์˜ ์ฑ…์ž„์ด ๋‹จ์ผ entity๋กœ ๋ฌถ์ž„

๋ฌธ์ œ์ 

โ€ข
Connection ๋ถ€๋ถ„ code ๋ณ€๊ฒฝ์ด data channel ๋‹ด๋‹น client code์˜ ์žฌ์ปดํŒŒ์ผ, ์žฌ๋ฐฐํฌ๋ฅผ ์š”๊ตฌํ•จ

ISP complied sample

โ€ข
์ฑ…์ž„ ๋ณ„ interface ๋ถ„๋ฆฌ๋ฅผ ํ†ตํ•ด ํŠน์ • client code ์™€์˜ action ๋ณ€๊ฒฝ์ด ํƒ€ client code์— ์˜ํ–ฅ์„ ๋ฏธ์น˜์ง€ ์•Š์Œ

Conclusion

โ€ข
SRP๋Š” class ์ˆ˜์ค€์—์„œ์˜ ๋†’์€ ์‘์ง‘๋„๋ฅผ ๊ฐ•์กฐํ•˜๋Š” ๋ฐ˜๋ฉด ISP๋Š” interface ์ˆ˜์ค€์˜ ์‘์ง‘๋„๋ฅผ ๊ฐ•์กฐ.
โ€ข
์–ด๋–ค class์˜ ์ฑ…์ž„์„ ๋ถ„๋ฆฌํ•  ์ˆ˜ ์—†์„ ๊ฒฝ์šฐ(SRP ์œ„๋ฐ˜), ์ตœ์†Œํ•œ interface๋งŒ์ด๋ผ๋„ ๋ถ„๋ฆฌํ•  ๊ฒƒ.

References

โ€ข
OOPrimer - (Object Oriented Principles Explained), Arnon Rotem-Gal-Oz
ooprimer.pdf
534.6KB