There is a class with inner classes:
public class ParentClass { //состояние объекта public class State { public void action(){} } public State currentState; public void setState(int stateID) { if(stateID==0) currentState = new Born(); if(stateID==1) currentState = new Life(); if(stateID==2) currentState = new Dead(); } //виды состояний public class Born extends State { @Overide public void action(){} } public class Life extends State { @Overide public void action(){} } public class Dead extends State {} @Overide public void action(){} } ///уделяем объекту внимание public void Action (){ currentState.action(); } } How to override in the successor the methods of the inner classes Born Life and Dead, without inheriting the classes themselves?
Задумка была простой 1. Обеспечить каждого наследника своей реализацией методов action(). 2. Оставить метод переключений состояния объекта setState() в родителе.