0

Firt of all, sorry for my "EngRish". I'm revisiting some of my project to make them more usable/understandable by my co-workers; I'm developing a framework for integrate a protocol driver to our SCADA system, in a nutshell i have an abstract class that provide some common functionalities that must specialized by the protocol driver, for example:

Opening a comunication with the field:

Called Method: void ConnectionOnScan(string connectionName)

In the base class i have something like this:

public void ConnectionOnScan(string connectionName)
{
  //... some preliminary operation here

  try
  {
    ConnectionOnScan(channelNumber);//provided by the derived class
  }
  catch (Exception e)
  {
   //some code here to properly register the fault to the SCADA System
  }
 }

The method that should be provided by the derived class should be (according to the system):

void ConnectionOnScan(UInt64 channelNumber)

Normally the driver must do something inside this method, in small cases this method can be empty.

My Goal is to let the develompent of a driver as simple as possible even for low-skilled programmers.

I have around 30 methods with the same use case: what will be best practice? declare them abstract or virtual (with an empty method)?

  • 1
    if definition to be supplied by derived class then virtual can be used what i think – Ehsan Sajjad Jan 05 '15 at 11:32
  • possible duplicate of [What is the difference between an abstract function and a virtual function?](http://stackoverflow.com/questions/391483/what-is-the-difference-between-an-abstract-function-and-a-virtual-function) – Sinatr Jan 05 '15 at 12:34

1 Answers1

2

You should ask yourself if you have to implement the method in the driver, or if it is optional.

In the first case you use abstract, in the second case you use virtual.

Peter
  • 27,590
  • 8
  • 64
  • 84
  • Unfortunately the same method, according to the specific driver can be optional or mandatory, so its better to consider everything optional or everything mandatory? – Salvatore Sorbello Jan 05 '15 at 11:40