| ▲ | munificent 6 hours ago | |
I wouldn't call it a good use of static typing, but I'd call it a good use of object-oriented programming. This is one of the really key ideas behind OOP that tends to get overlooked. A constructor's job is to produce a semantically valid instance of a class. You do the validation during construction so that the rest of the codebase can safely assume that if it can get its hands on a Foo, it's a valid Foo. | ||