Click here to Skip to main content
15,905,686 members
Home / Discussions / C#
   

C#

 
Questionneed to communicate with RS232 cable Pin
djtourist20-Nov-05 5:52
djtourist20-Nov-05 5:52 
AnswerRe: need to communicate with RS232 cable Pin
Ray Cassick20-Nov-05 6:54
Ray Cassick20-Nov-05 6:54 
GeneralRe: need to communicate with RS232 cable Pin
djtourist20-Nov-05 7:03
djtourist20-Nov-05 7:03 
GeneralRe: need to communicate with RS232 cable Pin
Colin Angus Mackay20-Nov-05 8:18
Colin Angus Mackay20-Nov-05 8:18 
GeneralRe: need to communicate with RS232 cable Pin
djtourist20-Nov-05 9:44
djtourist20-Nov-05 9:44 
GeneralRe: need to communicate with RS232 cable Pin
Colin Angus Mackay20-Nov-05 9:51
Colin Angus Mackay20-Nov-05 9:51 
Questionhelp me, about WMI Pin
newpant20-Nov-05 4:15
newpant20-Nov-05 4:15 
QuestionFactory Pattern Question With Generics Pin
nlecren20-Nov-05 3:57
nlecren20-Nov-05 3:57 
Ok i am struggling with the factory pattern big time. This pattern seems great if you are creating objects that share all the same properties but i can never find a sample client that uses the specific concrete classes that have different properteries. ( Ok that probably made no sense so here is a sample using generics )

public abstract class Vehicle
{
protected string name;
protected string type;

public Vehicle()
{
}

public Vehicle(string name)
{
this.name = name;
}

public string Name
{
get { return name; }
set { name = value; }
}

public string Type
{
get { return type; }
}
}

// a concrete vehicle
public class Car : Vehicle
{
public Car() : base()
{
}

public Car(string name, string type) : base(name)
{
base.type = type;
}
}

// another concrete vehicle

public class Truck : Vehicle
{
bool 4WD = false;

public Truck() : base()
{
}

public Truck(string name, string type) : base(name)
{
base.type = type;
}

public Engage4WD() // This only exists for a truck
{
4WD = true;
}
}


interface IVehicleFactory
{
T CreateObject<t>(string name) where T : Vehicle, new();
}

public class VehicleFactory : IVehicleFactory
{
public T CreateObject<t>(string name) where T : Vehicle, new()
{
// create instance of Type T where this type derives from Vehicle
T v = new T();
v.Name = name;

return v;
}
}

public class FactoryPatternUsingGenericMethod
{
static void Main(string[] args)
{
IVehicleFactory f = new VehicleFactory();
Car c = f.CreateObject<car>("Kitty");
Truck d = f.CreateObject<truck>("test");



}
}
}

It appears at this point i can get a truck or a car using the factory however what is the benefit of this. This just seems like alot of work when i could have just had a separate truck object and car object inheriting from vehicle and use the new operator without resorting to a factory. Would this not give the same result.

I guess i just can't seem to quite grasp what the big benefit is here for the presentation layer?
Thanks in advance
AnswerRe: Factory Pattern Question With Generics Pin
Daniel Turini20-Nov-05 4:51
Daniel Turini20-Nov-05 4:51 
GeneralRe: Factory Pattern Question With Generics Pin
nlecren20-Nov-05 14:27
nlecren20-Nov-05 14:27 
GeneralRe: Factory Pattern Question With Generics Pin
S. Senthil Kumar20-Nov-05 19:27
S. Senthil Kumar20-Nov-05 19:27 
QuestionHow to playback file wave by tapi Pin
sharapova20-Nov-05 3:13
sharapova20-Nov-05 3:13 
AnswerRe: How to playback file wave by tapi Pin
Ray Cassick20-Nov-05 8:25
Ray Cassick20-Nov-05 8:25 
QuestionRe: How to playback file wave by tapi Pin
sharapova22-Nov-05 4:26
sharapova22-Nov-05 4:26 
QuestionHow do i get a list of Currently running tasks? Pin
Anthony Mushrow20-Nov-05 3:08
professionalAnthony Mushrow20-Nov-05 3:08 
QuestionXmlTextReader - Enumerating Nodes Pin
matthias s.20-Nov-05 3:06
matthias s.20-Nov-05 3:06 
AnswerRe: XmlTextReader - Enumerating Nodes Pin
Rob Philpott20-Nov-05 10:00
Rob Philpott20-Nov-05 10:00 
GeneralRe: XmlTextReader - Enumerating Nodes Pin
matthias s.20-Nov-05 21:39
matthias s.20-Nov-05 21:39 
QuestionBackGroundImage of MDIForm in C#.Net Pin
Harshalbhakta20-Nov-05 2:13
Harshalbhakta20-Nov-05 2:13 
AnswerRe: BackGroundImage of MDIForm in C#.Net Pin
newpant20-Nov-05 4:15
newpant20-Nov-05 4:15 
GeneralRe: BackGroundImage of MDIForm in C#.Net Pin
Harshalbhakta21-Nov-05 14:28
Harshalbhakta21-Nov-05 14:28 
GeneralRe: BackGroundImage of MDIForm in C#.Net Pin
newpant22-Nov-05 1:31
newpant22-Nov-05 1:31 
Questiondisplay chronometer connected to parrallel port Pin
el_aristo20-Nov-05 2:11
el_aristo20-Nov-05 2:11 
Questionhow to use button to open the new form Pin
activesync20-Nov-05 2:05
activesync20-Nov-05 2:05 
AnswerRe: how to use button to open the new form Pin
Jeff Bramwell20-Nov-05 2:36
Jeff Bramwell20-Nov-05 2:36 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.