• Post Reply Bookmark Topic Watch Topic
  • New Topic

Object Concept Explanation  RSS feed

 
Kishor Joshi
Ranch Hand
Posts: 674
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi can someone explain state and behaviour of bicycle example listed in this doc?

http://docs.oracle.com/javase/tutorial/java/concepts/object.html

I know what are state and what is its behaviour.

I don't understand this line



By attributing state (current speed, current pedal cadence, and current gear) and providing methods for changing that state, the object remains in control of how the outside world is allowed to use it. For example, if the bicycle only has 6 gears, a method to change gears could reject any value that is less than 1 or greater than 6.





one more line



Pluggability and debugging ease: If a particular object turns out to be problematic, you can simply remove it from your application and plug in a different object as its replacement. This is analogous to fixing mechanical problems in the real world. If a bolt breaks, you replace it, not the entire machine.


can someone explain it in terms of software coding?



the one more is
http://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html


The byte data type is an 8-bit signed two's complement integer


what does it mean by two's complement integer?



you can use a short to save memory in large arrays,


what does it mean by saving memory in large arrays?


Thanks
 
Knute Snortum
Sheriff
Posts: 4279
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One topic per thread, please!

The part about the bike means that if an object knows how it's implemented, it is easier for it to test for reasonableness when data is entered.
 
Campbell Ritchie
Marshal
Posts: 56546
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I suggest you create a setGear method which insists on the gear being in the range 1−6. Start from this naïve implementation and enhance it.
 
Kishor Joshi
Ranch Hand
Posts: 674
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes ,

Now I understand it well
 
Campbell Ritchie
Marshal
Posts: 56546
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And what did you get for a method which sets a gear in the specified range?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!