We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
코드에서 상태(조건)를 명시적으로 확인하지 않는 속성이다.
| 문제 되는 프로그램 코드 보기
Manage : 식료품 가게에 대한 관리 프로그램 Product : 관리 대상 프로덕트
class Product { name; daysUntilExpiry; value; urgency; constructor(name, daysUntilExpiry, value) { this.name = name; this.daysUntilExpiry = daysUntilExpiry; this.value = value; } decrementExpiry() { return (this.daysUntilExpiry -= 1); } getUrgency() { this.urgency = this.value / this.daysUntilExpiry; return this.urgency; } } class Manager { products = []; constructor(products) { this.products = products; } viewProduct() { this.products.forEach((product) => { const urgency = product.getUrgency(); console.log(`${product.name} urgency: ${urgency}`); }); } filterExpireProduct() { this.products = this.products.filter( (product) => product.daysUntilExpiry > 0 ); } updateProducts() { this.products.forEach((product) => { product.decrementExpiry(); }); this.filterExpireProduct(); } } const apple = new Product("Apple", 5, 10); const carrot = new Product("Carrot", 3, 5); const lightBulb = new Product("Light Bulb", 0, 3); const manager = new Manager([apple, lightBulb]); manager.updateProducts(); manager.viewProduct();
[ 그 외 ]
+) 디스커션에 올릴지 이슈에 올릴지 고민이 돼서 이슈에 올렸는데 의견 주셔도 좋습니다 !
The text was updated successfully, but these errors were encountered:
2장의 호스트님이신 승희님을 태그했습니다.........^^!!! 교수님 믿습니다
Sorry, something went wrong.
1.daysUntilExpiry는 항상 양수인 불변속성이다.
daysUntilExpiry
daysUntilExpiry > 0
전구를 판매하기 시작함으로서 daysUntilExpiry는 양수가 아닌 0이 될 수 있게 되었다. 즉, 불변속성이 아니게 되었다.
해결방법은 불변속성이 깨진 변수를 �체크하거나, 불변속성의 범위를 제한하는 것이다.
getUrgency() { assert(this.daysUntilExpiry !== 0, new Error("~~"))) this.urgency = this.value / this.daysUntilExpiry; return this.urgency; }
sa02045
No branches or pull requests
불변속성이란 ?
코드에서 상태(조건)를 명시적으로 확인하지 않는 속성이다.
예제내용
(=> 전구에는 만료 일이 없다. 일수를 빼고 0에 도달하면 품목을 삭제하는 기능이 있지만 이렇게 하면 만료일이 없는 전구는 에러가 난다.)
범위가 제한되지 않은 불변속성은 어떻게 손상될까 ?
| 문제 되는 프로그램 코드 보기
Manage : 식료품 가게에 대한 관리 프로그램
Product : 관리 대상 프로덕트
[ 책 내용 ]
[ 그 외 ]
+) 디스커션에 올릴지 이슈에 올릴지 고민이 돼서 이슈에 올렸는데 의견 주셔도 좋습니다 !
The text was updated successfully, but these errors were encountered: