Hi!
I was really hoping that a 'Binary .NET Dissambly' would pick up a UML Dependency where I am instantiating a new class (it is not maintained, it lives only for the duration of the method) and is not a parameter passed in or out. Therefore the only way you could know about it is from code.
Perhaps my UML is wrong.. Is it not true that if a method in Class A instantiates Class B and calls services of Class B that you have a dependency now between Class A and Class B (uni-directional)?
I created an application to test this as I need it to calculate a metric I am working on for my book. I need to know about these dependencies but without a reverse engineering or access to code, there will be cases like this I don't know about.
Sparx doesn't show the dependency line on the class diagram, it only shows the Association that exists. Here is the code:
using System;
namespace UMLDependencyFailure
{
internal class Startup
{
[STAThread]
private static void Main(string[] args)
{
AnswerQuestion oAnswerer = new AnswerQuestion();
QuestionAsker oAsker = new QuestionAsker(oAnswerer);
bool Result = oAsker.IsSumOfIntegersTheSame(100, 50, 50);
Console.WriteLine(Result);
Console.Read();
}
}
}
namespace UMLDependencyFailure
{
public class QuestionAsker
{
private readonly AnswerQuestion _Answerer;
public QuestionAsker(AnswerQuestion oAnswerer)
{
_Answerer = oAnswerer;
}
public bool IsSumOfIntegersTheSame(int ExpectedSum, int SumOne, int SumTwo)
{
return _Answerer.IsQuestionTrue(ExpectedSum.ToString(), SumOne, SumTwo);
}
}
}
namespace UMLDependencyFailure
{
public class Calculator
{
public Calculator()
{}
public int AddTwoInts(int inOne, int inTwo)
{
return inOne + inTwo;
}
}
}
namespace UMLDependencyFailure
{
public class AnswerQuestion
{
public AnswerQuestion()
{}
public bool IsQuestionTrue(params object[] oParams)
{
Calculator oCalc = new Calculator();
int Result = oCalc.AddTwoInts(int.Parse(oParams[1].ToString()), int.Parse(oParams[2].ToString()));
return (Result == int.Parse(oParams[0].ToString()));
}
}
}
As you can see, in the AnswerQuestion class in the IsQuestionTrue method I create a new instance of :
Calculator oCalc = new Calculator();
and call:
int Result = oCalc.AddTwoInts(int.Parse(oParams[1].ToString()), int.Parse(oParams[2].ToString()));
This should of created a dependency but there isn't one. AM I WRONG? Is this NOT a UML Dependency?
Kind Regards,
Damon Carr, CEO
agilefactor
www.agilefactor.com