For example, imagine a futuristic society where computer-controlled robotic cars transport passengers through city streets without a human operator. Automobile manufacturers write software (Java, of course) that operates the automobile—stop, start, accelerate, turn left, and so forth. Another industrial group, electronic guidance instrument manufacturers, make computer systems that receive GPS (Global Positioning System) position data and wireless transmission of traffic conditions and use that information to drive the car.
The auto manufacturers must publish an industry-standard interface that spells out in detail what methods can be invoked to make the car move (any car, from any manufacturer). The guidance manufacturers can then write software that invokes the methods described in the interface to command the car. Neither industrial group needs to know how the other group's software is implemented. In fact, each group considers its software highly proprietary and reserves the right to modify it at any time, as long as it continues to adhere to the published interface.\
Abhay Bhatt wrote:My simple question is that how, in the case where we don't create/use any interface, the code of auto manufacturers and guidance manufacturers gets exposed to each other(which creates the need of an Interface in the first place)?
Suppose, in the above example, auto manufacturers implement an default method in the interface itself, so now does that default method code/implementation gets exposed to guidance manufacturers? If yes, then is using default methods, a trade off?
Stephan van Hulst wrote:
Car manufacturers must publish modules that contain the declarations of the methods that can be called, otherwise guidance manufacturers can't develop their software effectively. However, they are not required to publish the modules that implement these methods. They could install these modules right into the cars that they manufacture, even having them protected by the car's hardware. When they don't use interfaces to publish the method declarations, they must include their implementations with the published module, which can then be reverse engineered by the guidance manufacturers.
Stephan van Hulst wrote:
Yes, you could say that. However, usually default method implementations shouldn't be very complex, so I doubt anybody would care about reverse engineering them.
Abhay Bhatt wrote:Can you please tell me what do you mean by a 'published module'? My best guess would be that it might have something to do with access modifiers but then I am not sure.
But they can be complex, can't they? Is there a logic behind, functionality added later on, being, usually or always, relatively less complex or simpler, in nature?
Campbell Ritchie wrote:If the idea behind default methods was for adding functionality to existing interface, is there any need to write a default method in a new interface at all?