M
Macka
A few pieces of information first:
* I have a class called Folder which represents a row of data in a
database table. The data access side of things is not an issue.
* The table has a parent column which references itself (ie. Adjacency
or parent/child model)
* I have a public property called 'Parent' which returns me a new
reference to a Folder instance containing the data of the parent row.
eg.
public Folder Parent {
get {
//if the parent is available
if (_iParent > 0) {
//create a new instance of the folder object referring to the
parent
_parent = new Folder(_iParent);
}
return _parent;
}
}
* This means that I am able to access the current folders parent's,
parent's name like this (folder is an instance of Folder):
folder.Parent.Parent.Name;
Firstly, am I on the right track? Is this the recommended way to build
a self referencing class? Is there a design pattern which covers this
off ?
Secondly, Folder is an abstract concept. In practise I will actually
be dealing with an ImageFolder or a UserFolder. I'd like to make
Folder an abstract class, then create these other classes which can
inherit from Folder. The problem is that when I'm referencing the
Parent property, I need to be returning a new instance of the
ImageFolder/UserFolder rather than Folder.
Hope this makes sense!
Cheers,
macka.
* I have a class called Folder which represents a row of data in a
database table. The data access side of things is not an issue.
* The table has a parent column which references itself (ie. Adjacency
or parent/child model)
* I have a public property called 'Parent' which returns me a new
reference to a Folder instance containing the data of the parent row.
eg.
public Folder Parent {
get {
//if the parent is available
if (_iParent > 0) {
//create a new instance of the folder object referring to the
parent
_parent = new Folder(_iParent);
}
return _parent;
}
}
* This means that I am able to access the current folders parent's,
parent's name like this (folder is an instance of Folder):
folder.Parent.Parent.Name;
Firstly, am I on the right track? Is this the recommended way to build
a self referencing class? Is there a design pattern which covers this
off ?
Secondly, Folder is an abstract concept. In practise I will actually
be dealing with an ImageFolder or a UserFolder. I'd like to make
Folder an abstract class, then create these other classes which can
inherit from Folder. The problem is that when I'm referencing the
Parent property, I need to be returning a new instance of the
ImageFolder/UserFolder rather than Folder.
Hope this makes sense!
Cheers,
macka.