本文介绍了在Smalltalk中重构if-chains而没有类爆炸的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
由于Smalltalk不鼓励使用caseOf:,在没有类爆炸的情况下实现以下情况有哪些备选方案?
As Smalltalk discourages the use of caseOf:, what aternatives exists to implement the following situation without class explosion?
self condition1
ifTrue: [ self actionForCondition1 ]
ifFalse: [
self condition2
ifTrue: [ self actionForCondition2 ]
ifFalse: [
self condition3
ifTrue: [ self actionForCondition3 ]
ifFalse: [ .... ] ] ]
推荐答案
如果你滚动到接近结尾
你会发现句子
在Smalltalk中有四种表达案例陈述的方法。
"There are four ways to express a case-statement in Smalltalk."
后跟链接示例。
文本在稍微长一系列页面的中间,偶尔提到假设导师和学生参加Smalltalk课程以便说明;为了你的问题,你可以忽略它)
The text is in the middle of a slightly longer series of pages and makes occasional references to hypothetical tutor and students ina Smalltalk course for purposes of illustration; you can ignore that for the purposes of your question)
这篇关于在Smalltalk中重构if-chains而没有类爆炸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!