I am writing a method which should have default values for some of the parameters, but overloading seems like an inelegant solution. The method takes a Network as the first parameter, a NetworkNode as the second and a name as the third, and then passes those to the Network object to process. However, I want both the Network and name parameters to be optional and be used with default values if not defined; here's my first attempt:
// FIXME: addNode overloading is not elegant
def addNode(node: NetworkNode) = latestNetwork.addNode(node, "")
def addNode(node: NetworkNode, name: String) = latestNetwork.addNode(node, name)
def addNode(network: Network, node: NetworkNode) = network.addNode(node, "")
def addNode(network: Network, node: NetworkNode, name: String) = network.addNode(node, name)
That doesn't look too readable, though. I definitely want to have the Network as first parameter, and it would be very preferable for it to be optional. However, the following doesn't work:
def addNode(network: Network = latestNetwork, node: NetworkNode, name: String = "") = network.addNode(node, name)
Is there a way around this? Is overloading with defaults like this a practice that commonly is considered bad or frowned upon in the context of modular solutions?
Thank you for your time.