Hello. This is my first post here. I am a programmer with C and C++ experience, and lately I have been heavily programming in C#. I suppose it is quite common I don't use all features at once so, for the first time I am dealing with Interfaces. I would very much appreciate if someone can help me with understanding the following
I have an interface
and a class that implements it
I have this concept that interfaces are like abstract classes and can not be instantiated but in another class I have
So my questions are:
1) Even though Centroid implementes ITracker , the class anotherClass has as its member variable a ITracker _tracker. Why? How is this possible?
I have the suspicion that this is so that the member _tracker can be of class Centroid or any other class that also implements ITracker.
But if this is so, why not just use a base class?
2) I get that we use a propery (Tracker) to get a new _tracker. This property instantiate a Centroid it seems using a Tracker factory.
When is this property called??
(This is related with my next question)
3) Originally _tracker is null. When I do Tracker.CreateTargetModel() or Tracker.Track() am i calling the propertiy Tracker's get?? everytime?
My apologies for the beginner questions. I have been trying to understand a program that uses much more features that I am accustomed to, and i would really like to learn.
thanks in advance
I have an interface
C#:
public interface ITracker {
void CreateTargetModel(......);
void Track(.....);
Bitmap ProcessedImage { get;}
Dictionary<string, string> Information { get;}
}
and a class that implements it
C#:
public class Centroid: ITracker
{
}
I have this concept that interfaces are like abstract classes and can not be instantiated but in another class I have
C#:
public class anotherClass
{
ITracker _tracker =null;
private ITracker Tracker
{
get{
if(_tracker==null) _tracker= new TrackerFactory(TrackerType.CENTROID).Tracker;
return _tracker;
}
}
private void TrackObject()
{
Tracker.Track((Bitmap) image, .....);
}
private void CreateTarget()
{
Tracker.CreateTargetModel(....);
}
}
So my questions are:
1) Even though Centroid implementes ITracker , the class anotherClass has as its member variable a ITracker _tracker. Why? How is this possible?
I have the suspicion that this is so that the member _tracker can be of class Centroid or any other class that also implements ITracker.
But if this is so, why not just use a base class?
2) I get that we use a propery (Tracker) to get a new _tracker. This property instantiate a Centroid it seems using a Tracker factory.
When is this property called??
(This is related with my next question)
3) Originally _tracker is null. When I do Tracker.CreateTargetModel() or Tracker.Track() am i calling the propertiy Tracker's get?? everytime?
My apologies for the beginner questions. I have been trying to understand a program that uses much more features that I am accustomed to, and i would really like to learn.
thanks in advance