개체를 저장하는 데이터 구조가 public static
인 DataStructures
클래스가 있습니다. 객체를 데이터 구조에 추가하는 것은 수 많은 검사를 수행하고 프로세스를 기억하고 데이터를 재 배열해야하는 관련 프로세스입니다. Foo
이라는 또 다른 클래스에서 객체를 데이터 구조에 추가해야합니다. ObjectFeed
이라는 메서드를 사용하여 개체와 개체의 레이블을 매개 변수로 사용하여이 작업을 수행 할 수 있다고 생각했습니다. 레이블은 메소드에 오브젝트를 추가해야하는 데이터 구조를 알립니다. 단지뿐만 아니라 그 데이터에 액세스 할 수있는 방법에 매개 변수로 공공 데이터 구조를 전달적절한 데이터 구조에 개체를 추가하는 디자인
Public Class DataStructures
{
public static List<obj> object1Storage = new List<obj>();
public static List<obj> object2Storage = new List<obj>();
...
}
Public Class Foo
{
public void ObjectFeed(/* PARAMETERS */)
{
//Code that generates an object called inspectionObject
//inspection object has an associated enum Type
if(objectType == Type.Type1)
{
addObject(inspectionObject, DataStructures.object1Storage);
}
if(objectType == Type.Type2)
{
addObject(inspectionObject, DataStructures.object2Storage);
}
...
}
private void addObject(obj inspectionObject, List<obj> objStorage)
{
objStorage.Add(inspectionObject);
//And a lot more code
}
}
: 나는 또한 추가 할 객체를 걸릴 것 addObject
라는 방법 및 매개 변수로 적절한 대상 데이터 구조를 가질 것 구조가 직접적으로 정확하지 않습니다. 이 작업을 수행하는 데 더 영리하고 직관적 인 방법이 있습니까? 예 내가 원래 인위적인에서
의 ObjectFeed 방법은 뚜렷한 목적을 제공하지 : 편집
. 나는 실제 세계에서 더 많은 것을 보일 수있는 방법을 다시 썼다.