Showing posts with label State. Show all posts
Showing posts with label State. Show all posts

Monday, March 19, 2012

What is a Class? What is an object?

A class is a definition of all state/attributes & behavior belonging to an entity. The following figure is a UML class diagram for an entity called Player. The middle compartment lists each state/attribute of Player and the bottom compartment lists each behaviour of Player.

UML class diagrams are used to design classes. This design is then used to inform the code. It's like a blueprint for building a house.

Objects are created from classes - many objects may be created from a single class - in the same way as one blueprint can build many houses. The following figure is a UML object diagram showing the Player class along with 3 Player objects.

Notice that while each object has a strength and agility attribute, the values for these attributes are unique from object to object. From this diagram, we can see the state of each object.

The behaviours are not listed in the object diagram because all objects share the same behaviours.

"What Is a Class? (The Java™ Tutorials > Learning the Java Language > Object-Oriented Programming Concepts)" ( http://bit.ly/FUAjmF )