Код: Выделить всё
void setMyAttribute(MyAttribute value) {
this.myAttribute = value;
}
< /code>
цепный стиль: < /p>
MyObject setMyAttribute(MyAttribute value) {
this.myAttribute = value;
return this;
}
< /code>
И мне это очень нравится. Вот переходной код, где у меня все еще есть оба стиля: < /p>
this.organigramme.setCivilite(civilitePresident);
this.organigramme.setNomPresident(nomPresident);
this.organigramme.setPrenomPresident(prenomPresident);
Commune communeSiege = new Commune();
communeSiege.setSirenCommune(sirenCommuneSiege);
communeSiege.setCodeCommune(codeCommuneSiege);
communeSiege.setNomCommune(nomCommuneSiege);
communeSiege.setArrondissement(arrondissementSiege);
communeSiege.setPopulation(populationCommuneSiegeTotale);
Adresse adresseSiege = new Adresse()
.codePostal(codePostalSiege)
.complementVoie(complementAdresseSiege)
.bureauDistributeur(distributionSpecialeSiege)
.voie(libelleVoieSiege)
.ville(villeSiege);
this.siege.nomCommune(nomCommuneSiege)
.commune(communeSiege)
.nomCommune(nomCommuneSiege)
.adresse(adresseSiege)
.email(courrielSiege)
.siteInternet(siteInternetSiege);
Потому что сеттеры должны вернуть в своем прототипе. Вызывая, что я не могу выбрать желаемый заказ для их звонка, после этого. Я должен тщательно цепорить:
Если какой -либо установщик вызывается, когда я заполняю A B объект, они разбивают цепочку, не позволяя вызову любого B Setter снова:
Здесь компетенции Competencs c) определяется в базовом классе :
И это разочаровывает! Потому что, конечно, если b расширяет и что я заполняю объект B с некоторым классом A Setters, их возврат this; возвращают конкретный b класс! был абстрактным классом: < /p>
Код: Выделить всё
X a1(String value) {
this.a1 = value;
return this;
}
Подробнее здесь: https://stackoverflow.com/questions/796 ... base-class