I am working in C# some exercises and I don't understand the big picture. If these should implement in Java I wodn't have problems. But I am new in C# so I mixed up things and I don't know how te structure should look like. I read some explanasions like: http://www.codeproject.com/Articles/15360/Implementing-IDisposable-and-the-Dispose-Pattern-P and http://msdn.microsoft.com/en-us/library/fs2xkftw.aspx
I have first class where I make LinkedList and itst type is node, so: LinkedList linkedlist = new LinkedList than I make some nodes in puti it in linkedlist by some methods also here is method print, which prints elements from linkedlist.
My "object" class is Node, where I have constructors, properties and so getters and setters. I have allso here virtula method print and I don't know what shoudl I put in this method, becuse this node class is just abstract class and here I must implement IDisposable methods:
public void Dispose() {}
protected virtual void Dispose(bool disposing) {}
Here I don't undrsetend why should I use IDispose? In all examples I saw it has been used for access to some file and working with pictures. In some examples I saw:
public interface IDisposable
{
void Dispose();
}
and I don't know if I must put this in some new class, shuld I put it in the same class or even not implement it.
And than I make subclasses NodeLong and Nodestring which uses superclass node whre I put some new properties and setters and getters. I have also used print method. I also don't understand genercis.
Linearcollection class:
public class LinearCollection{
void Main(string[] args){
LinkedList<Node> linkedlist = new LinkedList<Node>
//calling methods for adding some elements, deleting, getting some elements
}
//implemented methods
public void Print(){
foreach( NodeElement item in linkedList){
// what to do??
}
}
My Nodeelemts class:
public abstract class Node:{
private bool _disposed;
//constructors
//properties, set, get ex:
private Object data;
public Object _data{
get{
rethurn this._data;
}
set{
this._data=value;
}
}
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
protected virtual void Dispose(bool disposing){
if(!_disposed){
if(disposing){
//disposed managed resources
}
//
}
_disposed = true;
//
}
virtual public void Print(){
//what to implemetn?
}
}
//stil the same file
public class NodeString : Node{
//prop
public string typeOfElement{ get set ...}
//new constructor where is involved new property
public overrride void Print()
{
Console.WriteLine(_data.ToString());
base.Print();
}
}
public class NodeLong : Node{
//prop
public long typeOfElement{ get set ...}
//new constructor where is involved new property
public overrride void Print()
{
Console.WriteLine(_data.ToString());
base.Print();
}
}
If I make NodeLang: IClonable than I cant make NodeLang:Node.
My instructions says that I must use IClonable methods in both subclasses, I don't know how should I use it? Also use IDisposable in class Node, how? I hope I am understandible?
So the finale question is how it should look like my class, subclass, IDisposable and ICloneable?