I have test code written in Python, using classes.
The test environment has two types of hosts - app hosts, where applications run, and storage hosts, where storage components run.
I have two classes, each representing the type of host:
class AppHost_Class(object):
def __init_(self, ip_address):
# etc.
# This method handles interfacing with the application
def application_service(self):
# This method handles the virtual storage component
def virtual_storage(self):
# This method handles caching
def cache_handling(self):
class Storage_Server_Class(object):
def __init_(self, ip_address):
# This method handles interfacing with the storage process
def storage_handling(self):
# This method handles interfacing with the disk handling processes
def disk_handling(self):
The problem is that the topology can change.
Topology #1 is this: - Application Host runs * Application processes * Virtual storage processes * Cache processes
- Storage Host runs
- Storage processes
- Disk handling processes
My current test code handles Topology #1
However, we also want to support another Topology (Topology #2)
Application Host runs
- Application processes
Storage Host runs
- Virtual storage processes
- Cache processes
- Storage processes
- Disk handling processes
How can I refactor the classes so that for Topology 1, the classes and its methods are the same, but for Topology 2, the Storage_Server_Class gets some of the methods from the AppHost_Class?
I was thinking of making a child class like this:
class Both_Class(AppHost_Class, Storage_Server_Class):
But I don't want to do this because I don't want the applcation_service method to be available to Both_Class.
Is there a way to just map a few methods in AppHost_Class into the Storage_Server_Class?
AppHost_Classinherits from and introduces theapplication_servicemethod to, and then inherit from that other class andStorage_Server_Classfor yourBoth_Class. Although - does it really matter if you have that method available in both class?