Answer Posted / guest
Strategy pattern is one of the 23 design patterns
available. The basic concept of strategy pattern is object
composition at runtime. When you have multiple classes each
having similar behaviour but the behaviour could change
based on an external factor or the object itself. For
example take a car, a car can have an engine, a steering
wheel, 4 tyres e.t.c but a remote control car will not have
an engine but will have the other characteristics of a
normal car. For this case let us have the following code:
Interface HasEngine
{
void Engine();
}
Interface Tyres
{
void 4Tyres();
}
class Hummer:HasEngine,Tyres
{
override void Engine()
{
Console.WriteLine("Has Engine");
}
override void 4Tyres()
{
Console.WriteLine("Has 4 tyres");
}
}
class RemoteCar:HasEngine,Tyres
{
override void Engine()
{
Console.WriteLine("Has no Engine");
}
override void 4Tyres()
{
Console.WriteLine("Has 4 tyres");
}
}
class Car
{
HasEngine HE;
Tyres T;
setEngine(HasEngine obj)
{
HE=obj;
}
setTyres(Tyres obj)
{
T=obj;
}
}
class MainClass:Car
{
HasEngine he;
Tyres tyr;
setInstance()
{
he = new Hummer();
tyr = new Hummer();
}
public static void Main()
{
MainClass mc = new Car();
mc.setInstance();
mc.setEngine(he);
mc.setTyres(tyr);
}
}
| Is This Answer Correct ? | 1 Yes | 1 No |
Post New Answer View All Answers
can any one tel me the complete Testing Procedure of any one simple PROJECT i mean either web/windows based application?
What is the difference between .net and laravel?
Can you create instance of a class which has private constructor?
Why is .net used?
What is the use of immutability?
What does il do?
Explain the features that are common to all .Net languages.
What data providers available in .net to connect to database?
Do you know what is lambda expressions in c#?
Which file is taken by compiler when we have both file Application and Server Configuration file?
Which namespace is used to support multithearding in .NET?
What is the need of OLE-automation?
Compare client server application with n-tier application
When we use windows api in .net is it managed or unmanaged code?
What is the difference between asp.net and asp?