PeanutsMonkey
PeanutsMonkey

Reputation: 7095

Correct UML semantics and syntax

I have 2 UML classes that are named owner and followed by vehicle.

I am wanting to know whether I can state that vehicle 'generalizes' owner as I would like the object vehicle to inherit attributes assigned to owner. It doesn't seem right as I wouldn't consider vehicle a subclass or subtype of owner but seeing I am new to UML, I'm no expert.

Upvotes: 2

Views: 139

Answers (2)

Xaelis
Xaelis

Reputation: 1599

You could use a common abstract class to regroup common attributes. Let say you want Owner and Vehicle to share a common name attribute. You could use the following model.

UML common attributes http://app.genmymodel.com/engine/xaelis/commonAttributes.jpg

Upvotes: 1

Jim L.
Jim L.

Reputation: 6529

You said, "vehicle 'generalizes' owner", but then said, "I would like the object vehicle to inherit attributes assigned to owner." Those two statements are contradictory because a superclass generalizes and a subclass specializes. Since you want Vehicle to inherit attributes from Owner, I'll assume you are asking whether you can state that Owner generalizes Vehicle (and Vehicle specializes Owner).

In the real world, it is not a true statement that every Vehicle is always a kind of Owner. What does your Car own? Do you mean that it "owns" its engine, wheels, and doors? Is that the same concept as "owning" your car or your home?

Classes are meant to represent more than buckets of reusable attributes and methods that allow you to seemingly save some coding time--although many programmers treat them as such. They are called classes because they represent classes of things in the problem domain (i.e., the "real world"). This is where many programmers go astray--they focus on things in the solution domain, which change much more rapidly, and they lose all the benefits of object orientation. One of the key tenets of OOA / OOP is that the problem domain changes infrequently, so it provides a relatively stable base upon which to build software. If you claim strange things, such as "a Vehicle is always a kind of Owner", you build on unstable sand and may spend lots of time fighting the tide later, when you find a case where the claim is not so convenient anymore. In what way is a Vehicle always an Owner? Would many business-oriented subject matter experts agree with you?

Upvotes: 4

Related Questions