I want a singleton Problem with a "square" 2x2.
I want to be able to refer to the case by row.
I want to be able to refer to the row by case.
I know I could easily do this in C++ with pointers but it seems like a bad habit to do.
I don't understand how to link my "row" and my "case" together.
The same logic will be there for column but isn't describe in the code
I want to be able to refer to the case by row.
I want to be able to refer to the row by case.
I know I could easily do this in C++ with pointers but it seems like a bad habit to do.
I don't understand how to link my "row" and my "case" together.
The same logic will be there for column but isn't describe in the code
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Debugging { class Program { static void Main(string[] args) { Problem.Instance().Show(); Problem.Instance().Change(); Problem.Instance().Show(); } public class Problem { private Case[] cases = null; private Row[] rows = null; // same logic with private Column[] columns = null; static Problem instance = null; private Problem() { cases = new Case[4]; rows = new Row[2]; int i = 0; for (i = 0; i < 4; i++) cases[i] = new Case(); for (i = 0; i < 2; i++) rows[i] = new Row(i); } public static Problem Instance() { if (instance == null) instance = new Problem(); return instance; } public Case LinkToRow(int i, Row r) { cases[i].LinkToRow(r); return cases[i]; } public void Show() { rows[0].Show(); } public void Change() { cases[0].Change(); cases[1].Change(); } } public class Row { private Case[] cases = null; public Row(int i) { cases = new Case[2]; cases[0] = Problem.Instance().LinkToRow(0, this); cases[1] = Problem.Instance().LinkToRow(1, this); } public void Show() { Console.WriteLine("{0},{1}", cases[0].Val, cases[1].Val); } } public class Case { private int val; private Row r = null; public Case() { } public void LinkToRow(Row rr) { r = rr; } public int Val { get { return val; } } public void Change() { val++; } } } }
Last edited by a moderator: