UML relationship between the same class - uml

I have an 'Account' class and (every) Account (instance) can have 0 or more guestAccounts (from the same 'Account' class).
I'm stuck of how to model this:
- should I model this as a unary association (recursive)?
Thanks for helping.

Yes indeed you can.
I am not sure that's solved your question, but you can do something like:
I define private for attributes visibility, public or default is often an error.

Related

UML Class Diagram - Generalization

This image illustrate the UML I must follow in this project.
The problem is, I don't know what means the private parameter "ator" in the arrow. It should be declared in the class Ator or Personagem? I do know that Personagem is a subclass of Ator.
Because the arrow is unidirectional, you can be sure that -ator should be placed just next to the Ator class. This implies that a private attribute ator exists for class Personagem.
Then, from any method in the Personagem class, you can use some code like this.ator.getId()

App Fabric : While GET misses an Enum property

I have a class marked as CollectionDataContract which has a enum member. When I place an object of this class in Appfabric, I am through. When I get it back from App fabric, it does not deserialize the enum member. But I am not sure if the enum has been missed out in Serialization part itself.
Please do help.
If you need more information let me know.
Thanks.
[CollectionDataContract]
public partial class RuleConditionList : List<IRuleCondition>, IRuleCondition
{
public LogicalOperator Operator;
}
where LogicalOperator is an enum
I think there is a problem when serializing/deserializing your object. AppFabric uses the NetDataContractSerializer class for serialization before storing the items in the cache.
You can use the Net­Dat­a­Con­tract­Se­ri­al­izer on any type which are marked with the Dat­a­Con­trac­tAt­tribute or Seri­al­iz­ableAt­tribute, or types that imple­ment the ISe­ri­al­iz­able interface.
So depending and your object, there should be something wrong like a private type, a private field, a missing attibute, ...
Edit
You should add DataMember to your field.
[DataMember]
public LogicalOperator Operator;
Any data member in a class marked with Collection data contract cannot be serialized by NetdataContractSerializer which is the serailization technique used by App fabric for storing data.
To make things work we have two options:
Make a wrapper for RuleConditionList
Instead of Inheriting from List, make it as a property and change the attribute as DataContract.

Casting Namespace

I have class name called "Address" in two namespaces. Its been two EDMX files, so it holds
different namespace in client side. I have another class "Vendor" and it holds object of "Address" class. In one situation i have to convert from one namespace to another namespace.
How i can achieve this.
You do not cast namespaces, you resolve types by qualifying them with a namespace.
Generally it is a bad idea to have multiple classes with the same name, especially if they are used together somewhere in the application.
It is not possible automatically. Namespace is really just a prefix of name of class. Essentially they are completely different classes with nothing in common.
Unless one Address class is derived from the other one, you cannot cast between the two at all. What you can do is give the classes some kind of "conversion constructor" that takes an object of the respective other class and maps the fields to its own ones:
namespace NS1
{
public class Address
{
// fields go here
public Address(NS2.Address add2)
{
this.Name = add2.Name;
this.Street = add2.Street;
// etc.
}
}
}
Casting namespace is conceptually incorrect. It’s more appropriate to say casting from one type to another. Unless the two classes are related in terms of inheritance, you cannot use casting at all.

Difference between association and dependency?

In a UML class diagram, what is the difference between an association relationship and a dependency relationship?
From what I know, an association is a stronger relationship than a dependency, but I'm not sure how it is stronger.
Any example would be more than welcome :)
An association almost always implies that one object has the other object as a field/property/attribute (terminology differs).
A dependency typically (but not always) implies that an object accepts another object as a method parameter, instantiates, or uses another object. A dependency is very much implied by an association.
In OOP terms:
Association --> A has-a C object (as a member variable)
Dependency --> A references B (as a method parameter or return type)
public class A {
private C c;
public void myMethod(B b) {
b.callMethod();
}
}
There is also a more detailed answer.
What is the difference between dependency and association?:
In general, you use an association to represent something like a field
in a class. The link is always there, in that you can always ask an
order for its customer. It need not actually be a field, if you are
modeling from a more interface perspective, it can just indicate the
presence of a method that will return the order's customer.
To quote from the 3rd edition of UML Distilled (now just out) "a
dependency exists between two elements if changes to the definition of
one element (the supplier) may cause changes to the other (the
client)". This is a very vague and general relationship, which is why
the UML has a host of stereotypes for different forms of dependency.
In code terms, such things as naming a parameter type and creating an
object in a temporary variable imply a dependency.
...
Dependency is like when you define a method that takes a String(in Java, C#, as string is a object in them) as a parameter, then your class is dependent on String class.
Association is like when you declare a string as an attribute in your class.
then your code is associated with the string class.
String name = null //: is a association.
Dependency - A change in a class affects the change in it's dependent class. Example- Circle is dependent on Shape (an interface). If you change Shape , it affects Circle too. So, Circle has a dependency on Shape.
Association- means there is a certain relationship between 2 objects
(one-one, one-many,many-many)
Association is of 2 types-
Composition
Aggregation
1) Composition- stronger Association or relationship between 2 objects. You are creating an object of a class B inside another class A
public class A {
B b;
public void setB(){
this.b= new B();
}
}
If we delete class A , B won't exist( B object is created inside A only).
Another example -Body & Liver .Liver can't exist outside Body.
2) Aggregation - weaker type of Association between 2 objects.
public class A {
B b;
public void setB(B b_ref){
this.b= b_ref;
/* object B is passed as an argument of a method */
}
}
Even if you delete class A, B will exist outside(B is created outside and passed to Class A)
Another example of this- Man & Car . Man has a Car but Man & Car exist independently.
Here: "Association vs. Dependency vs. Aggregation vs. Composition", you have a great vade mecum with uml class diagrams and code snippets.
The author gives us a list of relationships: Association, Dependency, Aggregation, Composition in one place.
A dependency is very general and lowering complexity is about diminishing dependencies as much as possible.
An association is a strong (static) dependency. Aggregation and Composition are even stronger.
I was always checking this answer as it didn't stick in my mind. I found this one more helpful after reading the accepted answer
Association is when one object just has a link to another and don't use relational object methods. For ruby for example
class User
has_one :profile
end
user = User.first
profile = user.profile
profile.sign_out
It means you can get a profile object from user but user don't use profile's methods inside himself(has no dependency on a Profile's interface).
Dependency means that User has link to another object and call that object's methods inside himself
class User
has_one :profile
def personal_info
profile.info
end
end
Here if Profile's info method will be changed or renamed our Dependent User class also need to be changed.

What does the '#' symbol mean in a UML class diagram?

I was reading Algorithms in a Nutshell (O'Reilly) and came across this symbol in a class diagram. My guess is that it means the member is protected, but I wanted to see if anyone knows for sure what it means.
It indicates a protected member of a class or other data type.
- Indicates private
+ Indicates public
# Indicates protected
Add also to :
~ Indicates package-private (or default)
'#' indicates the visibility. In this case it refers to a protected operation [ edited out the term 'method' as this is not as generic ].
'#' stands for visibility "protected" (similar to public,private ) behavior of the property/methods in the class . You can find more of the same at uml_basic_notations
It implies that it is protected, for a variable it will only be seen in the class and inherited classes.

Resources