Repartition is the root of all software evil
"Every piece of knowledge must have a single, unambiguous representation in the system"
"Repetition in logic calls for abstraction. Repletion in process calls for automation"
private static void Load() { using (var myConnection = new SqlConnection()) { myConnection.ConnectionString = "Data Source=localhost;initial Catalog=someCatalog;Integrated Security=True"; string myQuery = ""; using (var myCommand = new SqlCommand(myQuery, myConnection)) { myCommand.Parameters.Add(new SqlParameter("LastRunDate", new DateTime(1997, 1, 1))); var myAdapter = new SqlDataAdapter(myCommand); _invoiceTable = new DataTable("Invoices"); myAdapter.Fill(_invoiceTable); foreach (DataRow row in _invoiceTable.Rows) { Console.WriteLine("{0}--{1}--{2}", row[0], row[1], row[2]); } } } using (var myConnection = new SqlConnection()) { myConnection.ConnectionString = "Data Source=localhost;initial Catalog=someCatalog;Integrated Security=True"; string myQuery = ""; using (var myCommand = new SqlCommand(myQuery, myConnection)) { var myAdapter = new SqlDataAdapter(myCommand); _employeeTable = new DataTable("Employee"); myAdapter.Fill(_employeeTable); foreach (DataRow row in _employeeTable.Rows) { Console.WriteLine("{0}--{1}", row[0], row[1]); } } } }
Above you can see an example of a function that violates the DRY principle: can see an almost copy pasted code repeats it self