✅ Перевірена відповідь на це питання доступна нижче. Наші рішення, перевірені спільнотою, допомагають краще зрозуміти матеріал.
Tu equipo está desarrollando un . Se plantea una clase para la creación de criaturas de diferentes tipos, y la inicialización de éstas con unos atributos físicos y de comportamiento dados. Asumiendo clases (abstracta), un compañero te propone la siguiente implementación:
public class CreatureCreator {
public Creature newCreature(CreatureType type,
PhysicalAttributes physicalAttributes,
BehavioralAttributes behavioralAttributes) {
Creature creature = null;
if (type.equals(CreatureType.
creature = new Goblin();
} else if (type.equals(CreatureType.
creature = new Ogre();
} else if (type.equals(CreatureType.
creature = new Orc();
} else if (type.equals(CreatureType.TROLL)) {
creature = new Troll();
}
creature.setPhysicalAttributes(physicalAttributes);
creature.setBehavioralAttributes(behavioralAttributes);
return creature;
} // newCreature
}
Claramente ves inconvenientes (¿cuáles?) en la implementación, y le propones seguir el patrón . Te entrega el siguiente código:
public abstract class CreatureCreator {
public Creature newCreature(CreatureType type,
PhysicalAttributes physicalAttributes,
BehavioralAttributes behavioralAttributes) {
Creature creature = null;
creature = this.createCreature(type);
creature.setPhysicalAttributes(physicalAttributes);
creature.setBehavioralAttributes(behavioralAttributes);
return creature;
} // newCreature
public abstract Creature createCreature(CreatureType type);
}
Отримайте необмежений доступ до відповідей на екзаменаційні питання - встановіть розширення Crowdly зараз!