Wednesday, November 29, 2006

OOP 7

Here are some ideas that everyone should know about OOP:
  • Encapsulation
  • API
  • Receiver Relative
  • Inheritance

But, what about ideas that nobody likes to mention about OOP:

  • Coupling between two classes, i.e. loose or tight based on dependencies
  • Sometimes you just need a C++ type struct - an object with data but no operations on the data.
  • Knowledge Isolation - just make a change in one place is difficult under normal OOP design wherein you may have multiple objects accessing the file system idividually. A change to file system access would then have to be made in each object.

What is the idea behind Java inner classes?

Remember C++'s callback facility? Alice provides Bob a call back vis-a-vis a pointer. Bob stores the pointer and after some time passes, Bob can call the code in Alice's structure.

In Java and other OOP, you create an object that responds to various messages. You give Bob a pointer to this code which is in the Alice object. For example, passing an iterator to a client to iterate over members of an ArrayList.

Try making a Binary Tree class wherein the nodes are inner classes.

Try to make a nested class with static keyword and you will find that the inner class cannot access the outer class' instance vars.

What is AbstractCollection?

A factoring up of the various collection attributes.

Chad Salinas