|
|
||
| You are here: | ||
|
5.4 |
Main features of an object This page from the Java section covers the definition and terminology associated with objects. Encapsulation refers to the embedding of code that operates on an object's data members together with the data members and then not exposing details to other objects. Data members are almost always private - limited in scope to the Class that defines them. Access to those data members to change their state is via methods . Methods that change an object's state are usually referred to as "setter" or, more formally, mutator methods. Methods that return information about an object's state are usually referred to as "getter" or accessor methods. This means that internal representations used in objects can be changed without disturbing the external behaviou r of the object. Other code that uses the object is not aware of any changes so existiung code is not "broken". Polymorphism refers to the application of a method to several different types of object with each object behaving appropriately . Often an object will be a sub-class of another object. By default the subclass inherits all of the protected methods of the superclass . However, the subclass may choose to overload the inherited method - to change it to be more suitable to its own needs. In Java, and therefore JETS, all Classes which are defined inherit from Object - the ultimate superclass. The Object Class implements several methods, of which one of special interest, is the toString() method which returns a text description of the Object. Every Class which we create ought to override the toString() method to give a String representation of itself. Naturally this will be different for different objects - it is polymorphic. However, beware, it is not considered mastery of polymorphism just to do this. See, for example, the May 2006 Subject Report on the IB's Online Curriculum Centre. The Biscuit application which was developed as part of the core Java pages, demonstrates this. related: [ ADT home | previous: dynamic data structures | next: recursion ] |
Check out the OOP Terminology page |
|
|
|||
|
Questions or problems related to this web site should be addressed to Richard Jones who asserts his right to be identified as the author and owner of these materials - unless otherwise indicated. Please feel free to use the material presented here and to create links to it for non-commercial purposes; an acknowledgement of the source is required by the Creative Commons licence. Use of materials from this site is conditional upon your having read the additional terms of use on the about page and the Creative Commons Licence. View privacy policy. This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 2.5 License. © 2001 - 2009 Richard Jones, PO BOX 246, Cambridge, New Zealand; This page was last modified: May 31, 2009 |