View Latest Questions and Answers
View Latest Questions
Posted on: April 17, 2011 at 12:00 AM
This page discusses - OOP
OO Analysis & Design
Classes represent domain elements.
May permit reuse.
Other classes necessary
Patterns are standard ways to relate classes
UML is most common visual modelling technique
is-a vs has-a
One "instance" per object.
Declared out of methods.
Can not be refrenced from static context
static / class
static final used for constants.
Relatively little use outside of constants.
Can have static block initializers.
Only one value for class
Call from out of class qualified by object.
Call within class implicitly this.
Can access all instance and static members
class / static
Call from out of class qualified by class
Can also be qualified by object, which is ignored.
Can only access static members.
Useful if pure computation without state.
Eg, Math class.
classes - See inner classes below
Define all fields in consistent state.
Same as class name, no return type
Can be overloaded.
No-param constructor created if no user-defined.
If any defined, no default.
First line always calls other contructor
If none, a call on default super is made.
Refers to parent class constructor.
Refers to other constructors in class.
If all constructors private, no one can construct
Use Factory pattern (method returns new object).
Ignore - like C++ destrurctors, but may not be called.
Result in .class files with $
Inner class instances have implict reference to an outer class instance.
Reference to outer class instance with Outer.this.
Usually created from within outer class.
Can create from outside with eg, new Outer().new Inner()
Named, inside class
Instances need outer instance.
Can reference outer instance variables.
Reference to outer instance is OuterClass.this.
Defined in a method.
Commonly used for listeners.
Can reference outer class's instance members.
Can reference method's final local variables.
static nested top-level
declared static inside outer class
Only used for name scope
Can not reference outer classes instance variables.
A class is abstract if it doesn't implement all methods.
Must be subclassed to create an object.
Interfaces are like completely abstract classes.
final classes can not be extended (eg, String)
Lists methods which must be defined to implement
Can define public static final constants
Casting from a subclass to a superclass.
No explicit cast is required.
No run-time check required.
Casting from a superclass to a subclass/interface.
Requires explicit cast notation.
Run-time check performed (ClassCastException)
== vs equals()
Visible only in same class.
Should be used for data variables.
Write getter/setter methods if changeable.
Can be seen by anyone
Commonly used for methods.
can only be seen by child class.
can be seen by everyone in package
Allocated on heap with new.
Garbage collected when no references.
Used to group classes and other packages.
Default package if none specified.
Superclass - subclass
Parent - child
Base - derived
Anscestor - descendant
Can extend only one parent class.
Can implement multiple interfaces.
Object is the root of class hierarchy.
Child class can redefine methods of anscestor class.
toString() is commonly overridden.
Concatenation calls toString()
equals(...) is commonly overridden
A variable may contain an object of its class, or any subclass.
A call to a method will call the correct class's method.
A method can call super to call overridden method.
Defining methods which differ in number or types of parameters.
Eg, Integer, Float, Character, ...
"Wrap" a primitive value.
Provide a home to utility functions.
Create immutable objects.
Java 5 autoboxing - automatic conversion to/from primitive/wrapper.
Related Tags for OOP:
Web Design Packages
Web Promotion Services
Search Eng. Optimization
Search Eng. Submission
Web Promotion Plans
Web Hosting Services
© All Rights are Reserved for Rose India