I have multiple classes in this project that all face the same situation that I am about to explain. To simplify things I will use one class and the details of it's specific situation.
Class
class ConnectedDevice(object):
def __init__(self, mac_address, ip_address):
self.mac_address = mac_address
self.ip_address = ip_address
Way To Go About This # 1
I could construct instances with the member variables filled via parameters of the constructor.
This would be done by having separate functions outside of the class within main that get the necessary information.
def main():
mac_address = get_mac_address()
ip_address = get_ip_address()
Device0 = ConnectedDevice(mac_address, ip_address)
Way To Go About This # 2
I could construct instances with None in the parameters of the constructor and use member functions after the fact to fill the member variables. Obviously, I would have defined member functions in my class to do so.
def main():
Device0 = ConnectedDevice(None, None)
Device0.set_mac_address()
Device0.set_ip_address()
Question
I am asking which is the better Object Oriented way to go about this?
- Way To Go About This # 1
- Way to Go About this # 2