Feeds

Code inheritance and reuse: a delicate balancing act

The pot of gold at the end of many rainbows

Providing a secure and efficient Helpdesk

There are two primary concepts that are used extensively within Java (and indeed other OO languages) to promote reuse - inheritance and componentisation.

For many people, inheritance is the obvious (and classic) example of how to achieve reuse within Java systems. However, the ability to plug components together is equally important. Here a component can be anything from a class that implements an interface and is "plugged together" with a class that uses the protocol defined by the interface to JavaBeans; to much larger components such as a JMS system, or transaction management system. The key is that the component is used as is, without any modification.

Typically, within the literature on languages such as Java, the focus is often on inheritance (particularly in tutorial or training/educational materials). However, in practice, the reuse of components can be equally (if not more) important.

One way to distinguish between inheritance-based reuse and compositional reuse is that inheritance-based reuse is primarily developer-oriented ("developer" here refers to those developing the functionality of the elements which might comprise a component); while compositional reuse is user-oriented (that is, no further development of the component takes place).

In the following we will briefly look at inheritance oriented reuse (and its role) and component based reuse.

Inheritance-oriented reuse

Below we consider how classes can be modified through inheritance, and the dangers associated with this. Then, we propose the use of composition to promote reuse in some situations.

Categories of extension

When inheritance is used, an existing class (the superclass) is extended to create a new class (the subclass). The way in which it is extended can be categorised as modifications to the external protocol of the superclass; or as changes to the behaviour (implementation) of methods. These two categories are considered in more detail below.

Changes to the external protocol

When a subclass adds new methods that are available outside the class, it changes the external protocol of the superclass. This happens in a number of different situations:

  • The subclass adds entirely new methods.
  • The subclass provides convenience wrappers for existing methods.
  • The subclass restricts methods provided by the superclass. This may include removing methods, or changing method parameters to types that are more restrictive. Currently, there is no way in Java to restrict the methods inherited from a class.

Changes in the implementation of the methods

If a subclass overrides a superclass's methods, then it modifies the behaviour of the superclass. Again, there are a number of different situations within which this can happen:

  • The subclass provides a service for the superclass by overriding a method (structural inheritance).
  • The subclass needs to perform additional actions when a method is called (functional inheritance).
  • The subclass needs to replace the behaviour in a particular method (functional inheritance).

Internet Security Threat Report 2014

Next page: Compositional reuse

More from The Register

next story
UNIX greybeards threaten Debian fork over systemd plan
'Veteran Unix Admins' fear desktop emphasis is betraying open source
Netscape Navigator - the browser that started it all - turns 20
It was 20 years ago today, Marc Andreeesen taught the band to play
Redmond top man Satya Nadella: 'Microsoft LOVES Linux'
Open-source 'love' fairly runneth over at cloud event
Chrome 38's new HTML tag support makes fatties FIT and SKINNIER
First browser to protect networks' bandwith using official spec
Admins! Never mind POODLE, there're NEW OpenSSL bugs to splat
Four new patches for open-source crypto libraries
prev story

Whitepapers

Forging a new future with identity relationship management
Learn about ForgeRock's next generation IRM platform and how it is designed to empower CEOS's and enterprises to engage with consumers.
Why and how to choose the right cloud vendor
The benefits of cloud-based storage in your processes. Eliminate onsite, disk-based backup and archiving in favor of cloud-based data protection.
Three 1TB solid state scorchers up for grabs
Big SSDs can be expensive but think big and think free because you could be the lucky winner of one of three 1TB Samsung SSD 840 EVO drives that we’re giving away worth over £300 apiece.
Reg Reader Research: SaaS based Email and Office Productivity Tools
Read this Reg reader report which provides advice and guidance for SMBs towards the use of SaaS based email and Office productivity tools.
Security for virtualized datacentres
Legacy security solutions are inefficient due to the architectural differences between physical and virtual environments.