我想學習如何創建簡單的groovy類,這不是域類。我想在我的軟件中創建一組類(及其對象),但無意保存到數據庫。具體來說,我有一個關於如何創建一個屬性是第二類的列表的類的問題。像這樣:創建groovy類
class oParent{
def fName
def lName
def listOfChildren
}
class oChild{
def propertyOne
def propertyTwo
}
所以,用這個例子,我可以創造這樣每一個對象:
def p = new oParent();
def cOne = new oChild();
def cTwo = new oChild();
p.fName ="SomeName"
p.lName ="some Last Name"
cOne.propertyOne = "a"
cOne.propertyTwo = "b"
cTwo.propertyOne = "c"
cTwo.propertyTwo = "d"
那麼,如何添加每個子對象(錐CTWO)至父對象p)。一旦添加,我將如何遍歷父類的子元素屬性,例如,打印所有子類的所有propertyTwo屬性?
任何特別的理由下來票呢? – jason
也許是因爲奇怪的類和實例名稱。一種輕描淡寫的理由,但你永遠不知道。 –