Goldman Sachs Interview Question
Financial Software DevelopersNot yet sure what works best, but here are some thoughts I can throw around:
1) If D has no other data members, consider collpasing into one class, get rid of other, either B or D.
2) If that's not desired, create a separate function(s) to process args. Make it the friend function of both B and D, thereby comitting first degree murder of OOP concepts. But, you've accomplished what you wanted (ONE place to update). Bad part is, friend function will need all the logic to differentiate betn B and D inside.... or would it?!
3) Your thoughts here.
you could use the Builder design pattern. You could create a inner class named Builder or Buildable with setter methods for all the mandatory variables of the outer class and a build method. The caller calls each of the set methods on the Builder class and at the end calls the build method, which sets all the outer class variables and returns an instance of the outer class. You could also NOT provide any setter methods in the outer class, so that the outer class can be constructed only through the inner class build method
The parameters could be of type struct.
- Sameer Deshpande September 30, 2009