Someone please give me some idea to solve this question ? Should I use Interface or I can use only Heritage ?

Write classes implementing the management industrial tools:
* Each one tools can be started, stopped or be stopped urgently.
* There are three families of tools :
1. Electric : characterized by an input voltage and watt
2. Hydraulic : characterized by a pressure in bar at the entry
3. Mechanic : characterized by a power
* In the event of error, the tools start an exception.

Write a class which contains a function allowing to create tools dynamically. This function receives in parameter the name of the tools.

I think you'd go with inheritance to solve the problem. Think of it this way, for example, you're implementing a vehicle and different types of it. You'd have a vehicle class that has the main functionality which is shared by different types such as trucks, cars and so on. In truck and car classes you'd have functions that are just specific to them.

In your example, you'd have the main management industrial tool class which implements functions that will be shared by other classes like electric, hydraulic and mechanic.

in the case of your program catching the error, you'd check for the appropriate errors such as checking the input if it is a number, string or others depending on what the program is expecting. If the program fails in getting the right input, then it throws or deals with the error.

I hope that makes sense and helps you a bit.

Yes, I understand what u said. Thanks

in c#, you may use an abstract class for Tools and a derivated class for each of the tools.

commented: So, I just create classes abstract for Tools (Electric, Hydraulic & Mechanic) and derivated class for Started, Stopped & Stopped urgently. Am I right ? +0

So, I just create abstract classes for Tools (Electric, Hydraulic & Mechanic) and derivated classes for Started, Stopped & Stopped urgently. Am I right ?

Not exactly. Create an abstract class Tools, with methods for Start, Stop ...

Then create a derivated class for Electric, another one for Hydrolic and so on.
Derivated classes inherit the properties and methods defined in the abstract class.
Eventually, you may override these properties and methods in the derivated class, if a distinct processing is needed.

For instance, if the Start method is distinct for Hydrolic and Electric, you can override the Start method in each of these classes.

See MSDN for more information :
http://msdn.microsoft.com/en-us/library/k535acbf(VS.71).aspx

Well, finaly I decide to chose inheritance way but I don't know if my code is correct or not. Please check.

Write classes implementing the management industrial tools:
*Each one tools can be started, stopped or be stopped urgently.
* There are three families of tools :
1. Electric : characterized by an input voltage and watt
2. Hydraulic : characterized by a pressure in bar at the entry
3. Mechanic : characterized by a power
* In the event of error, the tools start an exception.

Write a class which contains a function allowing to create tools dynamically. This function receives in parameter the name of the tools.

/* MAIN */
static void Main(string[] args)
{
  /*
   * Electric
   * Hydraulic
   * Mechanic
   */
    Object obj;

     Tools objTool = new Tools();
     obj = objTool.CreateInstance("Electric");
}



/* TOOLS */
class Tools:Base
{
  public object CreateInstance(string typeName)
  {
    foreach (Assembly objAssembly in AppDomain.CurrentDomain.GetAssemblies())
      foreach (Type objType in objAssembly.GetTypes())
        if ((typeName == objType.Name) || (typeName == objType.FullName))
            return Activator.CreateInstance(objType);
      return null;
   }
}


/* ELECTRIC */
class Electric:Base
{
  protected int iVoltage;
  protected int iWatt;

  public Electric(int iA, int iB) { iVoltage = iA; iWatt = iB; }
}


/* HYDRAULIC */
class Hydraulic:Base
{
  protected int iBar;

  public Hydraulic(int iBar)
  {
      this.iBar = iBar;
   }
}


/* MECHANIC */
class Mechanic:Base
{
  protected int iPower;

  public Mechanic(int iPower)
  {
     this.iPower = iPower;
  }
}


/* BASE */
class Base
{
  public void setStarted()
  {
     Console.WriteLine("Start");
  }

  public void setStopped()
  {
     Console.WriteLine("Stopped");
  }

  public void setStoppedUrgently()
  {
     Console.WriteLine("Stopped Urgently");
  }
}//FIN Cls.
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.