M
Manuel Kampert
Hi,
while playing around as an hobby programmer for the last decade
I have now decided to dive deeper into the object oriented design
and programming paradigm.
To learn more about the OO story I have decided to write a small
network management system.
I have created the following (simplified) object model:
------------ ------------
| | /\| |
| Device |--------------| Ports |
| |1 n\/| |
------------ ------------
/|\
|
-------------|-------------
| | |
------------ ------------ ------------
| | | | | |
| HP | | Cisco | | Telesyn |
| | | | | |
------------ ------------ ------------
the classes HP, Cisco and Telesyn represent an switch or an hub on an
network.
Every such device has an amout of ports that it makes available to the
network to connect PCs, printers, workstation and the like to it.
Each switch or hub on the network provides a way to see which device
(address)
is connected to its port. The way how this is managed differs from
manufacturer
to manufacturer (i.e. SNMP query ifTable, SNMP query some entersprise
specific information base, use telnet,...).
So what I have at the moment is an pure virtual function in the
Device object named "QueryPorts() = 0;" This function is defined in
the classes HP, Cisco and Telesyn and querys for an address connected
to a port.
The algorithm that I use to get the device address from a hub or a
switch, update the database, check if the port already exists on the
database, ... is - except on some detail on how to ask the port for
the mac address - identical.
My question here is if it is better to try to write the algorithm as
generic
as possible in the base class and then add only what differs in the
derived
class? (of course not writing QueryPorts() as pure virtual, but having
some "pure virtual helper function)
Or is it better to copy and paste the alorithm to the derived classes
and leave the pure virtual function as it is (having to duplicate most
of the algorithm in all the derived classes)
Or maybe I am not thinking object oriented at all?
Many thanks in advance,
Manuel
while playing around as an hobby programmer for the last decade
I have now decided to dive deeper into the object oriented design
and programming paradigm.
To learn more about the OO story I have decided to write a small
network management system.
I have created the following (simplified) object model:
------------ ------------
| | /\| |
| Device |--------------| Ports |
| |1 n\/| |
------------ ------------
/|\
|
-------------|-------------
| | |
------------ ------------ ------------
| | | | | |
| HP | | Cisco | | Telesyn |
| | | | | |
------------ ------------ ------------
the classes HP, Cisco and Telesyn represent an switch or an hub on an
network.
Every such device has an amout of ports that it makes available to the
network to connect PCs, printers, workstation and the like to it.
Each switch or hub on the network provides a way to see which device
(address)
is connected to its port. The way how this is managed differs from
manufacturer
to manufacturer (i.e. SNMP query ifTable, SNMP query some entersprise
specific information base, use telnet,...).
So what I have at the moment is an pure virtual function in the
Device object named "QueryPorts() = 0;" This function is defined in
the classes HP, Cisco and Telesyn and querys for an address connected
to a port.
The algorithm that I use to get the device address from a hub or a
switch, update the database, check if the port already exists on the
database, ... is - except on some detail on how to ask the port for
the mac address - identical.
My question here is if it is better to try to write the algorithm as
generic
as possible in the base class and then add only what differs in the
derived
class? (of course not writing QueryPorts() as pure virtual, but having
some "pure virtual helper function)
Or is it better to copy and paste the alorithm to the derived classes
and leave the pure virtual function as it is (having to duplicate most
of the algorithm in all the derived classes)
Or maybe I am not thinking object oriented at all?
Many thanks in advance,
Manuel