java - call get methods for different classes behind one another -
i have class name "constituentset". has 1 method namely "getnucleusinconstset()" output "proposition" class . new class "proposition" have method namely "getproperty()". want know propertry of "proposition nucleus" in class "constituentset". not know how can that. wrote follow not work. (constituentset.getnucleusinconstset()).getproperty())
public class constituentset{ // constructor private proposition nucleusinconstset; public proposition getnucleusinconstset() { return nucleusinconstset; } } public class proposition{ //constructor private property property; public property getproperty() { return this.type; } }
you have:
(constituentset.getnucleusinconstset()).getproperty()
but need call instance of constituentset
e.g.
constituentset cs = new constituentset(); cs.getnucleusinconstset().getproperty();
note idiom (chained method calls) can pain. if 1 of methods returns null, it's difficult understand 1 (without using debugger). note invocations of form a().b().c().d()
subtle form of broken encapsulation (a
reveals has b
, reveals has c
etc.)
Comments
Post a Comment