E210 Conflict in Methods
[Previous]  [Next] 
|
User Manual [Previous]  [Next] E210 Conflict in MethodsUmple semantic error related to having two methods with the same signature but different implementationTraits can be used in several hierarchies without any priority. It means that classes can be composed of several traits and a trait can be composed of other traits. This brings cases in which two methods with the same signature come from either different traits or a different hierarchy path. If those methods come from two different traits, it is obvious that there is a conflict because those have been implemented for different purposes. On the other hand, if two methods come from two different paths but the source of those methods is the same trait, then there is no conflict. However, there is a case in which the source is the same but one of the methods is overridden by traits somewhere in the path. In this case, there is a conflict because now, the functionality is not unique. The Umple compiler detects these cases and raises this error. Example// In this example, there is a conflict // in class "A" on the method "test()". class A{ isA T1; isA T2; } trait T1 { void test(){ //special implementation by T1 } } trait T2 { void test(){ //special implementation by T2 } } Load the above code into UmpleOnline Another Example// In this example, there is // a conflict in trait "T" // on the method "test()". class A{ isA T; } trait T{ isA T1; isA T2; } trait T1{ void test(){ //special implementation by T1 } } trait T2{ void test(){ //special implementation by T2 } } Load the above code into UmpleOnline Solution to The Above So the Message No Longer Appears// In this example, there is a // no conflict in class "A". class A{ isA T1; isA T2; } trait T1 { isA M; } trait T2 { isA M; } trait M{ void test(){ //special implementation by M } } Load the above code into UmpleOnline Another Example// In this example, there is a conflict // in class "A" because method "test" // is overridden in trait "T2". class A{ isA T1; isA T2; } trait T1 { isA M; } trait T2 { isA M; void test(){ //special implementation by T2 } } trait M{ void test(){ //special implementation by M } } Load the above code into UmpleOnline |