Both Ada and Modula-2 separate out the interface from the implementation:
Ada package specification package body Modula-2 definition module implementation moduleAlthough a similar idea can be achieved in C++, it is not so cleanly done. In Java, interfaces can be used:
Java interface declaration class declaration
public interface Date; { public int getDay(); ... public void setDay(int pDay); ... } public class DateImpl implements Date { private int iYear; private int iMonth; private int iDay; ... public int getDay() { return iDay; } ... public void setDay(final int pDay) { iDay = pDay; } ... }
The lectures stress that code should be written in terms of the interface and that the name of the class should only be used when you want to create an object (of the class that implements the interface):
Date tTodaysDate = new DateImpl(2000, 1, 24); ... private static boolean iIsLeap(final Date pDate) { final int tYear = pDate.getYear(); return (tYear%400==0) || (tYear%4==0 && tYear%100!=0); }