what is the differences between class and dataType
Asked Answered
S

2

9

As i read through UML specification that:

 class has a set of attributes/operations
and data type has a set of attributes/operations

1)with regards to attributes/operations of data type what this means?

because i don't know how such a data type has attributes and operations?

2)What’s the main difference between a class and a datatype?

Soerabaja answered 3/4, 2013 at 6:36 Comment(0)
J
12

according to UML 2.4.1 specification

A data type is a special kind of classifier, similar to a class. It differs from a class in that instances of a data type are identified only by their value. All copies of an instance of a data type and any instances of that data type with the same value are considered to be equal instances. Instances of a data type that have attributes (i.e., is a structured data type) are considered to be equal if the structure is the same and the values of the corresponding attributes are equal. If a data type has attributes, then instances of that data type will contain attribute values matching the attributes.

1)Attributes/operations of data type have the same meaning than attributes/operations of classes i.e. attributes represent the structure of your data type and operations represent the method available on your data type.

2)The main difference between a class and a datatype is that it is not possible to have two instances of a datatype with the same values (these instance would be one unique instance).

Hoping it helps,

RB

Jeuz answered 3/4, 2013 at 14:1 Comment(0)
P
0

In the Object Oriented (OO) approach , systems , including software , are made up of numerous objects that work together by exchanging information in the form of data values and ‘messages’ . An object is a specific instance of a Class like your dog (an object) is specific instance of the class of all dogs. Classes define what an object is like, and objects are practical instances that can be used and manipulated. As a definition, a class defines what properties will be used to describe every object based on this class. Within the object each of these properties will have a value that contributes to its description. Two objects of the same class will have the same properties, but they will have at least one property that has a different value in each of the objects – if all the properties have the same values in both of the two objects then they are the same object.

A data type refers to the attributes of an object and what type of data each attribute is, such as string, boolean, integer etc.

Operations or methods is what an object can do such as for a dog:

growl();
bark();
fetch();

etc.

Have a look at this explanation of a Class Diagram, it will make more sense.

Peck answered 3/4, 2013 at 13:47 Comment(1)
"if all the properties have the same values in both of the two objects then they are the same object" That's actually incorrect. Assuming a simple Dog class as per your example, e.g. with two attributes name and age, it's perfectly fine to have two distinct instances of Dog, both named Fido and both aged 6.Mott

© 2022 - 2024 — McMap. All rights reserved.