Luc14860 / jwebsocket

Automatically exported from code.google.com/p/jwebsocket
0 stars 0 forks source link

Token class breaks encapulation and object state #130

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
Token token = new Token();
token.setNS("my.name.space");
token.setType("myType");
// print out the state of the object.  All good so far.
System.out.println("NS: "+token.getNS()+", Type: "+token.getType() );

token.setJSONObject(json);
// print out the state of the object again.  
System.out.println("NS: "+token.getNS()+", Type: "+token.getType() );
// OOps!  the values are null!  

What is the expected output? What do you see instead?
The expected output should be the internal state of the object. i.e. is should 
still have the values namespace and type that were set previously. This breaks 
the encapsulation rule of object oriented programming.

The same problem exists if the Token were to be instantiated using the an 
argument constructor e.g. new Token("my.name.space","myType")
The constructor should have the task of initializing the object's data members 
and of establishing the invariant of the class, failing if the invariant isn't 
valid. A properly written constructor will leave the object in a valid state.  
This breaks the object oriented contract of instantiation.

A consumer of an instance of Token should not have to worry about the ORDER in 
which the message are sent.  Currently, if using setJSONObject() with a 
consumer application's data, the NS and type cannot be set until AFTER the call 
to set the json.

What version of the product are you using? On what operating system?
version 0.10
web app deployed on Tomcat.

Please provide any additional information below.

Original issue reported on code.google.com by BrianUnd...@gmail.com on 10 Jun 2011 at 2:11

GoogleCodeExporter commented 9 years ago

Original comment by fivefeetfurther@gmail.com on 15 Jun 2011 at 4:14