In this article, I will focus on the concept of invariance. I will cover covariance and contravariance in upcoming articles. Type Systems play a big role in programming languages. In computations, we deal with values. Every value has some type. Who assigns types to the values? The answer is the type system. Wrongly assigned types to values may crash the whole program at … [Read more...] about Solid Code Design – Part 4 – Advanced Java Generics
Java Language
Solid Code Design – Part 3 – Subtyping and Java
This article is the continuation of the topic “Subtyping and Java” that we started in Part 1 of the series Solid Code Design. In Part 2, we discussed preconditions, postconditions, invariants, Java subtyping and true subtypes. In this article, we will focus on subtyping and Java generics. Suppose we have designed a class named IntegerPrinter, as … [Read more...] about Solid Code Design – Part 3 – Subtyping and Java
Solid Code Design – Part 2 – Subtyping and Java
This article is the continuation of the topic "Subtyping and Java" that we started in Part 1 of the series Solid Code Design. To start with we will touch upon the concept of specification and implementation aspects of a class. We will limit our focus only within Java Classes. A class's specification is a detailed description of what it exactly does. In other words, a … [Read more...] about Solid Code Design – Part 2 – Subtyping and Java
Solid Code Design – Subtyping and Java
This article is Part 1 of the series Solid Code Design. We will start this article with the below diagram. The above diagram defines a type hierarchy with a type, called SuperType, at the top of the hierarchy. Another important point is that subtypes can have subtypes. How do you define a type hierarchy in Java? In Java, we define a type hierarchy using inheritance. … [Read more...] about Solid Code Design – Subtyping and Java