I’ve run into a class that’s 2,000+ lines. It has two constructors – a simple one, and a complex one. Most of the methods work well for both constructors, but there are a few methods will either fail or behave oddly if the object is instantiated with the simple constructor.
Inheritance in this case is possible, but it’d be a bit weird. It’s not a different object, it’s just a different constructor.
Throwing an exception on a call to a method that requires the complex constructor would be an ugly patch.
Is there a standard refactor or pattern that solves this?
If your intent is that the availability of methods depends on which constructor is called, then they should be different objects.
It would be better to define separate classes, or to fix your constructors to both create valid objects with all methods functional.
If you decide it really should be one class, a common pattern that might help with this is “chained constructors”, where your simpler constructor calls the more complex constructor with appropriate default values for the missing parameters.
If on the other hand, you decide to go with two classes, it might be an inheritance relation, with the more complex class extending the simpler one, or it might sensibly be a composite relation, where the more complex class contains a field which is an object of the simpler class, and delegates some functionality to the other.
More concrete and definite advice would require seeing some code (but not 2000+ lines) exhibiting the issue.