Welcome to Dream.In.Code
Getting C# Help is Easy!

Join 132,383 C# Programmers for FREE! Get instant access to thousands of C# experts, tutorials, code snippets, and more! There are 1,192 people online right now. Registration is fast and FREE... Join Now!




UML notation for properties?

 
Reply to this topicStart new topic

UML notation for properties?

Zeddicus
post 30 Aug, 2008 - 11:01 PM
Post #1


New D.I.C Head

*
Joined: 14 Jul, 2008
Posts: 41


My Contributions


I'm reading a book for the moment where the author creates a class called Person and a corresponding class diagram in UML. The problem is that he does not distinguish between methods and properties in the diagram:

-------------------------------------------------------------------------
nbspnbspnbspnbspnbspPerson
-------------------------------------------------------------------------
birthday : DateTime
name : string
phone : string
-------------------------------------------------------------------------
Person(birthday : DateTime, name : string, phone : string)
Phone() : string
Name() : string
Birthday() : DateTime
NextBirthday() : DateTime
-------------------------------------------------------------------------


The code looks like this (with some modifications by me, one of the reasons being that the textbook is written in Swedish):

csharp

class Person
{
private DateTime birthday;
private string name;
private string phone;

public Person(DateTime b, string n, string p)
{
birthday = b;
name = n;
phone = p;
}

public string Phone
{
get { return phone; }
set { phone = value; }
}

public string Name
{
get { return name; }
}

public DateTime Birthday
{
get { return birthday; }

}


public DateTime NextBirthday()
{

DateTime next = new DateTime(DateTime.Today.Year, birthday.Month, birthday.Day);

if (next < DateTime.Today)
{
nästa = new DateTime(DateTime.Today.Year + 1, birthday.Month, birthday.Day);

}

return next;
}

}




Why does he not separate between a method (e.g. NextBirthday()) and a property (e.g. Name()) in the UML Class Diagram? Does he mean that a property is recognizable only because it is named after its attribute, with the only difference being the upper-case initial letter? Is this in line with the recommendations of the UML language?

Another thing that annoyes me is that the author does not use + and - for public and private in the UML diagram. crying.gif smile.gif

This post has been edited by Zeddicus: 31 Aug, 2008 - 01:33 AM
User is offlineProfile CardPM

Go to the top of the page

AdaHacker
post 31 Aug, 2008 - 08:01 PM
Post #2


D.I.C Head

**
Joined: 17 Jun, 2008
Posts: 162



Thanked 23 times
My Contributions


QUOTE(Zeddicus @ 31 Aug, 2008 - 02:01 AM) *

Why does he not separate between a method (e.g. NextBirthday()) and a property (e.g. Name()) in the UML Class Diagram?

It's a judgement call. The UML doesn't have a way of representing C# properties exactly, so he picked an attribute and a similarly named operation. Perhaps not the best choice, but the use of the same name does suggest that the operation encapsulates the attribute, and the best way to do that in C# is with a property. Another way would be to simply use a public attribute, but that might not suggest the encapsulation.

QUOTE(Zeddicus @ 31 Aug, 2008 - 02:01 AM) *

Does he mean that a property is recognizable only because it is named after its attribute, with the only difference being the upper-case initial letter? Is this in line with the recommendations of the UML language?

To quote Martin Fowler, "there is no hard-and-fast correspondence getween UML and code." You might model a property as a method, you might model it as a public attribute, or you might use a Java-ism and model it as a private attribute with corresponding public get and set operations. There's no one right way to do it. The implementor should interpret the diagram in light of his lanugage and use the most appropriate construct.
User is online!Profile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 11/22/08 06:32AM

Live C# Help!

C# Tutorials

Reference Sheets

C# Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month