Advanced Java/Reuse

From Wikiversity

Jump to: navigation, search
Crystal Clear app kaddressbook.png
Please help develop this page

This page was created, but so far, little content has been added. Everyone is invited to help expand and create educational content for Wikiversity. If you need help learning how to add content, see the editing tutorial and the MediaWiki syntax reference.

To help you get started with content, we have automatically added references below to other Wikimedia Foundation projects. This will help you find materials such as information, media and quotations on which to base the development of "Advanced Java/Reuse" as an educational resource. However, please do not simply copy-and-paste large chunks from other projects. You can also use the links in the blue box to help you classify this page by subject, educational level and resource type.

Wikipedia-logo.png Run a search on Advanced Java/Reuse at Wikipedia.
Commons-logo.svg Search Wikimedia Commons for images, sounds and other media related to: Advanced Java/Reuse
Wikimedia-logo.svg Search for Advanced Java/Reuse on the following projects:
Smiley green alien whatface.svg Lost on Wikiversity? Please help by choosing project boxes to classify this resource by:

The term reuse describes one of the four pillars of object oriented software systems academically referred to as Inheritence.

In Java, objects can be declared as an extension of another object. While there may be new or changed methods, Java will also inherit the existing methods of the original object.

[edit] Reuse example

The most common example of reuse is used in various Graphical User Interfaces. The most basic example would be a checkbox used to toggle something on or off. A radio button can be a subclass of this checkbox and reuse existing code, but is also given the ability to automatically uncheck similar radio buttons within a given group.

[edit] Resue limitations

An example that will cause problems with reuse is the difference between a Square and Rectangle. While you could in theory try to declare a Square as a subclass of Rectangle (or vice versa), they are defined differently. A square is a figure with four equal sides, while a rectangle has both opposite sides the same length. Attempting to declare a square as a subclass of rectangle will cause problems if you try resizing the shape as if it were a Rectangle (preventing reuse in that instance), and you cannot subclass a rectangle under a square since not all rectangles are squares.

As such, rules of inheritance may not function as expected even if it would appear to make sense in mathematics.