Connascence of Type

Connascence of type is the second lowest level of connascence in the static category, just above name. Connascence of type refers to when multiple components must agree on the type of a particular entity. This can be the explicit type in a statically typed language like Java, where most type issues will be guaranteed to be correct by the compiler. It can also be the implicit type that’s expected in a dynamically types language like Javascript, where type issues will either cause runtime exceptions or just weird behaviour to occur. 

Consider the following classes:

Our classes have connascence of type, both in the class declaration and in the method declaration. If we try to get our DinosaurHandler to handle a Chicken instead, she’s not going to be very happy- our dinosaur handler is coupled to the Dinosaur based on it’s type. If we try to feed the dinosaur anything except Food- like say the dinosaur handler herself- things aren’t going to be pretty. Both of our components are dependent on being called and created with the correct types of objects.

Like connascence of name, you can’t really get rid of connascence of type either- we’re always going to have either:

A) an explicit contract stating we will only work on this type of thing, and don’t even try giving us anything else, or

B) an implicit contract stating that ok sure, give us anything but don’t expect us to work properly if it’s not what we’re expecting.

This is the reason connascence of type is only one level above connascence of name- types are an incredibly important aspect of programming and are inherent to the way that we program.

Author: Sean O'Toole

I like development and I like dinosaurs. Here we are.

Leave a Reply

Your email address will not be published. Required fields are marked *