English 中文(简体)
如何通过 OOP 传输 ifelse 代码段?
原标题:How to transfer ifelse code segment by OOP?

我知道我应该按条件分解方法, 并安装每个子类的接口, 但我不知道客户类别 如何使用它, 你能给我简单的样本吗?

 public void buildInfoItemUpdater() {
    for (int i = 0; i < this.projectInfoInputItemUpdaters.size(); i++) {
        if (this.projectInfoInputItemUpdaters.get(i) instanceof ComboBoxUpdater) {
            ComboBoxUpdater tempItem = (ComboBoxUpdater) this.projectInfoInputItemUpdaters.get(i);
            projectInfoInputItemUpdaters.get(i).setAnswer(tempItem.getUserAnswer());
        } else if (this.projectInfoInputItemUpdaters.get(i) instanceof TextBoxUpdater) {
            TextBoxUpdater tempItem = (TextBoxUpdater) this.projectInfoInputItemUpdaters.get(i);
            projectInfoInputItemUpdaters.get(i).setAnswer(tempItem.getUserAnswer());
        } else if (this.projectInfoInputItemUpdaters.get(i) instanceof TextFieldUpdater) {
            TextFieldUpdater tempItem = (TextFieldUpdater) this.projectInfoInputItemUpdaters.get(i);
            projectInfoInputItemUpdaters.get(i).setAnswer(tempItem.getUserAnswer());
        }
    }
}

提前感谢您

最佳回答
问题回答

暂无回答




相关问题
Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

JSON with classes?

Is there a standardized way to store classes in JSON, and then converting them back into classes again from a string? For example, I might have an array of objects of type Questions. I d like to ...

Object-Oriented Perl constructor syntax and named parameters

I m a little confused about what is going on in Perl constructors. I found these two examples perldoc perlbot. package Foo; #In Perl, the constructor is just a subroutine called new. sub new { #I ...

Passing another class amongst instances

I was wondering what is the best practice re. passing (another class) amongst two instances of the same class (lets call this Primary ). So, essentially in the constructor for the first, i can ...

Where can I find object-oriented Perl tutorials? [closed]

A Google search yields a number of results - but which ones are the best? The Perl site appears to contain two - perlboot and perltoot. I m reading these now, but what else is out there? Note: I ve ...

热门标签