How to store/deal with data available to other classes

I’m writing a CAD program. Let’s say I have in input class, this class reads various data from a text file and creates lots of lists/dictionaries and …. These data need to be accessed by other methods in other classes to be modified. Now here is how I have done it so far:

I have one static class: Building.cs When I create/or load a project this class holds all the data like list of columns, beams, points, etc. All of these are stored as private fields. I can access these using the class’s public methods like GetColumns or GetPoints …

Now I also have non-static classes. They contain 2-3 public methods. and do some stuff on various parts of the building.

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>public static class Building
{
private static List<Column> columns;
private static List<Beams> beams;
private static List<Points> points;
public static List<Column> GetColumns()
{
return Columns;
}
}
public class ColumnsService()
{
private List<Columns> columns;
public GroupColumns(List<Columns> columns)
{
this.columns = columns;
}
public void Group()
{
// group columns
}
}
var columns = Building.GetColumns();
var columnsService = new ColumnsService(columns);
columnsService.Group();
</code>
<code>public static class Building { private static List<Column> columns; private static List<Beams> beams; private static List<Points> points; public static List<Column> GetColumns() { return Columns; } } public class ColumnsService() { private List<Columns> columns; public GroupColumns(List<Columns> columns) { this.columns = columns; } public void Group() { // group columns } } var columns = Building.GetColumns(); var columnsService = new ColumnsService(columns); columnsService.Group(); </code>
public static class Building
{
    private static List<Column> columns;
    private static List<Beams> beams;
    private static List<Points> points;

    public static List<Column> GetColumns() 
    {
        return Columns;
    }
}

public class ColumnsService()
{
    private List<Columns> columns;
    public GroupColumns(List<Columns> columns)
    {
        this.columns = columns;
    }

    public void Group()
    {
        // group columns
    }
}

var columns = Building.GetColumns();
var columnsService = new ColumnsService(columns);
columnsService.Group();

I was wondering is this the way to go? How else can I store the data. The data needs to be accessible throughout the lifetime of the program to most of the classes.

3

Because in your first question you professed a lack of knowledge about dependency injection, I will explain it in simple terms:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>public class ThingThatNeedsABuilding
{
private Building building;
public ThingThatNeedsABuilding(Building building)
{
this.building = building;
}
}
public class OtherThingThatNeedsABuilding
{
private Building building;
public OtherThingThatNeedsABuilding(Building building)
{
this.building = building;
}
}
public class Application
{
public static void Main(string[] args)
{
var building = new Building();
var thing1 = new ThingThatNeedsABuilding(building);
var thing2 = new OtherThingThatNeedsABuilding(building);
}
}
</code>
<code>public class ThingThatNeedsABuilding { private Building building; public ThingThatNeedsABuilding(Building building) { this.building = building; } } public class OtherThingThatNeedsABuilding { private Building building; public OtherThingThatNeedsABuilding(Building building) { this.building = building; } } public class Application { public static void Main(string[] args) { var building = new Building(); var thing1 = new ThingThatNeedsABuilding(building); var thing2 = new OtherThingThatNeedsABuilding(building); } } </code>
public class ThingThatNeedsABuilding
{
  private Building building;
  public ThingThatNeedsABuilding(Building building)
  {
    this.building = building;
  }
}

public class OtherThingThatNeedsABuilding
{
  private Building building;
  public OtherThingThatNeedsABuilding(Building building)
  {
    this.building = building;
  }
}

public class Application
{
  public static void Main(string[] args)
  {
    var building = new Building();
    var thing1 = new ThingThatNeedsABuilding(building);
    var thing2 = new OtherThingThatNeedsABuilding(building);
  }
}

It’s really that simple. The same instance of building is now shared between those two instances and nothing else. This is important. You do not want more stuff than needed to be available. This helps you avoid it.

If an object needs something, by all means give that something to it. Making it globally accessible to all objects makes it hard to tell if your program will even run, because an issue in the configuration of the dependency may cause a crash, but you can’t tell at initialization that an object even has that dependency.

There are other important reasons to inject dependencies, but that one is very simple to understand and very hard to reject.

4

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa

How to store/deal with data available to other classes

I’m writing a CAD program. Let’s say I have in input class, this class reads various data from a text file and creates lots of lists/dictionaries and …. These data need to be accessed by other methods in other classes to be modified. Now here is how I have done it so far:

I have one static class: Building.cs When I create/or load a project this class holds all the data like list of columns, beams, points, etc. All of these are stored as private fields. I can access these using the class’s public methods like GetColumns or GetPoints …

Now I also have non-static classes. They contain 2-3 public methods. and do some stuff on various parts of the building.

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>public static class Building
{
private static List<Column> columns;
private static List<Beams> beams;
private static List<Points> points;
public static List<Column> GetColumns()
{
return Columns;
}
}
public class ColumnsService()
{
private List<Columns> columns;
public GroupColumns(List<Columns> columns)
{
this.columns = columns;
}
public void Group()
{
// group columns
}
}
var columns = Building.GetColumns();
var columnsService = new ColumnsService(columns);
columnsService.Group();
</code>
<code>public static class Building { private static List<Column> columns; private static List<Beams> beams; private static List<Points> points; public static List<Column> GetColumns() { return Columns; } } public class ColumnsService() { private List<Columns> columns; public GroupColumns(List<Columns> columns) { this.columns = columns; } public void Group() { // group columns } } var columns = Building.GetColumns(); var columnsService = new ColumnsService(columns); columnsService.Group(); </code>
public static class Building
{
    private static List<Column> columns;
    private static List<Beams> beams;
    private static List<Points> points;

    public static List<Column> GetColumns() 
    {
        return Columns;
    }
}

public class ColumnsService()
{
    private List<Columns> columns;
    public GroupColumns(List<Columns> columns)
    {
        this.columns = columns;
    }

    public void Group()
    {
        // group columns
    }
}

var columns = Building.GetColumns();
var columnsService = new ColumnsService(columns);
columnsService.Group();

I was wondering is this the way to go? How else can I store the data. The data needs to be accessible throughout the lifetime of the program to most of the classes.

3

Because in your first question you professed a lack of knowledge about dependency injection, I will explain it in simple terms:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>public class ThingThatNeedsABuilding
{
private Building building;
public ThingThatNeedsABuilding(Building building)
{
this.building = building;
}
}
public class OtherThingThatNeedsABuilding
{
private Building building;
public OtherThingThatNeedsABuilding(Building building)
{
this.building = building;
}
}
public class Application
{
public static void Main(string[] args)
{
var building = new Building();
var thing1 = new ThingThatNeedsABuilding(building);
var thing2 = new OtherThingThatNeedsABuilding(building);
}
}
</code>
<code>public class ThingThatNeedsABuilding { private Building building; public ThingThatNeedsABuilding(Building building) { this.building = building; } } public class OtherThingThatNeedsABuilding { private Building building; public OtherThingThatNeedsABuilding(Building building) { this.building = building; } } public class Application { public static void Main(string[] args) { var building = new Building(); var thing1 = new ThingThatNeedsABuilding(building); var thing2 = new OtherThingThatNeedsABuilding(building); } } </code>
public class ThingThatNeedsABuilding
{
  private Building building;
  public ThingThatNeedsABuilding(Building building)
  {
    this.building = building;
  }
}

public class OtherThingThatNeedsABuilding
{
  private Building building;
  public OtherThingThatNeedsABuilding(Building building)
  {
    this.building = building;
  }
}

public class Application
{
  public static void Main(string[] args)
  {
    var building = new Building();
    var thing1 = new ThingThatNeedsABuilding(building);
    var thing2 = new OtherThingThatNeedsABuilding(building);
  }
}

It’s really that simple. The same instance of building is now shared between those two instances and nothing else. This is important. You do not want more stuff than needed to be available. This helps you avoid it.

If an object needs something, by all means give that something to it. Making it globally accessible to all objects makes it hard to tell if your program will even run, because an issue in the configuration of the dependency may cause a crash, but you can’t tell at initialization that an object even has that dependency.

There are other important reasons to inject dependencies, but that one is very simple to understand and very hard to reject.

4

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa

How to store/deal with data available to other classes

I’m writing a CAD program. Let’s say I have in input class, this class reads various data from a text file and creates lots of lists/dictionaries and …. These data need to be accessed by other methods in other classes to be modified. Now here is how I have done it so far:

I have one static class: Building.cs When I create/or load a project this class holds all the data like list of columns, beams, points, etc. All of these are stored as private fields. I can access these using the class’s public methods like GetColumns or GetPoints …

Now I also have non-static classes. They contain 2-3 public methods. and do some stuff on various parts of the building.

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>public static class Building
{
private static List<Column> columns;
private static List<Beams> beams;
private static List<Points> points;
public static List<Column> GetColumns()
{
return Columns;
}
}
public class ColumnsService()
{
private List<Columns> columns;
public GroupColumns(List<Columns> columns)
{
this.columns = columns;
}
public void Group()
{
// group columns
}
}
var columns = Building.GetColumns();
var columnsService = new ColumnsService(columns);
columnsService.Group();
</code>
<code>public static class Building { private static List<Column> columns; private static List<Beams> beams; private static List<Points> points; public static List<Column> GetColumns() { return Columns; } } public class ColumnsService() { private List<Columns> columns; public GroupColumns(List<Columns> columns) { this.columns = columns; } public void Group() { // group columns } } var columns = Building.GetColumns(); var columnsService = new ColumnsService(columns); columnsService.Group(); </code>
public static class Building
{
    private static List<Column> columns;
    private static List<Beams> beams;
    private static List<Points> points;

    public static List<Column> GetColumns() 
    {
        return Columns;
    }
}

public class ColumnsService()
{
    private List<Columns> columns;
    public GroupColumns(List<Columns> columns)
    {
        this.columns = columns;
    }

    public void Group()
    {
        // group columns
    }
}

var columns = Building.GetColumns();
var columnsService = new ColumnsService(columns);
columnsService.Group();

I was wondering is this the way to go? How else can I store the data. The data needs to be accessible throughout the lifetime of the program to most of the classes.

3

Because in your first question you professed a lack of knowledge about dependency injection, I will explain it in simple terms:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>public class ThingThatNeedsABuilding
{
private Building building;
public ThingThatNeedsABuilding(Building building)
{
this.building = building;
}
}
public class OtherThingThatNeedsABuilding
{
private Building building;
public OtherThingThatNeedsABuilding(Building building)
{
this.building = building;
}
}
public class Application
{
public static void Main(string[] args)
{
var building = new Building();
var thing1 = new ThingThatNeedsABuilding(building);
var thing2 = new OtherThingThatNeedsABuilding(building);
}
}
</code>
<code>public class ThingThatNeedsABuilding { private Building building; public ThingThatNeedsABuilding(Building building) { this.building = building; } } public class OtherThingThatNeedsABuilding { private Building building; public OtherThingThatNeedsABuilding(Building building) { this.building = building; } } public class Application { public static void Main(string[] args) { var building = new Building(); var thing1 = new ThingThatNeedsABuilding(building); var thing2 = new OtherThingThatNeedsABuilding(building); } } </code>
public class ThingThatNeedsABuilding
{
  private Building building;
  public ThingThatNeedsABuilding(Building building)
  {
    this.building = building;
  }
}

public class OtherThingThatNeedsABuilding
{
  private Building building;
  public OtherThingThatNeedsABuilding(Building building)
  {
    this.building = building;
  }
}

public class Application
{
  public static void Main(string[] args)
  {
    var building = new Building();
    var thing1 = new ThingThatNeedsABuilding(building);
    var thing2 = new OtherThingThatNeedsABuilding(building);
  }
}

It’s really that simple. The same instance of building is now shared between those two instances and nothing else. This is important. You do not want more stuff than needed to be available. This helps you avoid it.

If an object needs something, by all means give that something to it. Making it globally accessible to all objects makes it hard to tell if your program will even run, because an issue in the configuration of the dependency may cause a crash, but you can’t tell at initialization that an object even has that dependency.

There are other important reasons to inject dependencies, but that one is very simple to understand and very hard to reject.

4

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật