依存関係の管理を本当に理解しているかどうかはわかりません。別のクラスの詳細だけに依存していないということですか?呼び出し自体が正しいこととは何の関係もありませんか?私はより小さな、より具体的なクラスを作るために聞き続けていますが、彼らはお互いに依存することができず、これは私には不可能のようです。誰かが私にこれを簡単に説明しようとすることができますか?以下にいくつか例を示します。
//Bad Dependency
public class TestOne
{
TestTwo testTwo;
public void TestOneMethod()
{
testTwo = new TestTwo();
testTwo.SomeProperty = "Value";
testTwo.SomeMethodThatWorksWithSomeProperty();
}
}
//Bad dependency??
public class TestOne
{
TestTwo testTwo;
public void TestOneMethod()
{
int myInt = 0;
TestThree testThree = new TestThree();
//... Some Code that works with testThree
testTwo = new TestTwo();
myInt = testTwo.GetSomeInteger(testThree);
}
}
実行ごとに設定できる設定は1つだけですが、新しいクラスが呼び出されるたびにデータベースにアクセスし続ける必要があるのはなぜですか?これは悪い依存関係ですか
public static class Application
{
public static int SomeSetting = 0;
public static GetSettingsFromDatabase()
{
//loads the settings for this store
DatabaseClass dbClass = DatabaseClassDataSource.LoadForStore();
SomeSetting = dbClass.SomeSetting;
}
}
public class MyClass
{
public void MethodOne()
{
if(Application.SomeSetting == 1) { //... }
}
}
public class MyClassTwo
{
public void MethodOne()
{
if(Application.SomeSetting == 1) { //... }
}
}