Links

Lists

Latest Updates

Ruby On Rails List
Python list
Advanced Java
The JavaScript List
Apache Users
Full Disclosure
Linux Security

Search the archives!


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Question about "data hiding" OOP paradigm issue


  • From: Sordini.Emmanuele@xxxxxxxxxxxxxx (Sordini Emmanuele)
  • Subject: Question about "data hiding" OOP paradigm issue
  • Date: Thu, 30 Mar 2000 17:19:54 +0200

Dear All,
I've got to pose a question to you all java gurus.
Suppose I want to follow the well-known rule of making a class member
directly unaccessible to other callers by making it either private,
protected or "package-visible" (no explicit access modifier). That member
will be manipulated only through methods such as getter and setter. 
Suppose I have the following snippet of code (please don't mind coding
style):


// MyClass defined somewhere else: it has a method called
// doSomething()

class MyMainClass
{
  protected MyClass theObject;
  
 ...
  
  public void setTheObject(MyClass obj)
  {
    theObject = obj;     
  }

  public MyClass getTheObject()
  {
    return theObject;
  }

  public static void main(String[] args)
  {
    MyMainClass main = new MyMainClass();
    MyClass mc = new MyClass();

    main.setTheObject(mc);

    // Somewhen later...
    mc.doSomething();
  }
}

1)	When I call mc.doSomething() the state of mc is changed, and so is
the state of theObject. Or am I wrong? Feeding the setter with a reference
to mc is quite performance-effective, but clearly breaks OOP visibility
rules.
2)	If, on the other hand, I passed the setter a copy of mc, that would
ensure respecting the rule but would generate some memory and performance
overhead, which is not advisable given Java's generally poor scores.

Anybody have any opinions / hints?
Any help would be greatly appreciated.

Yours
Emmanuele

---
To unsubscribe, mail advanced-java-unsubscribe@xxxxxxxxxxxxxxxx
To get help, mail advanced-java-help@xxxxxxxxxxxxxxxx