So I'm working with a State Design Pattern in Java. I was hoping someone could explain the use of this in a Constructor. I understand that this is used for constructor chaining, but how does it work?
Example:
public class DegreeConstroller
{
private DegreeState firstState, secondState, thirdState, fourthState, curState;
private ArrayList<myObj> objs;
private String number, variable;
//Assume four other states and all other instance vars. have been initialized
public DegreeController(String number, String variable)
{
thirdState = new thirdState(this); <----------------
curState = firstState;
}
}
- What is
thisreferencing? - How is
thisreferencing that? (see #1) - Why is
thisneeded instead of something else?
All referring to the State Design Pattern
Aucun commentaire:
Enregistrer un commentaire