Hello I'm try to understand one example of UML to represent a System of vending machine. In this example are 3 classes Customer, Item and Balance. The problem here is Why Balance is represented as independent Object. I don't understand why because I think that should be a Customer attribute. Could help me to understand why?
Thanks.
Because it is important to the modeled domain.
Think of it this way: attribute and association is the same thing (Association Class vs. Attribute), only you visualize it differently.
In the very same sense you could have a class Image
to which Customer
would point, or class String
to which association name
would point.
However since you are modeling a vending machine state, you care about who (Customer) is buying what (Item) with which resources (Balance).
p.s. (unrelated to question, but related to the model): generally don't add accessor methods to your models, they are superficial, and login/logout sounds to me like overloading of concepts