Archive

Archive for the ‘C#’ Category

If I could have just one thing!

August 10th, 2008 Simon Segal No comments

Again today came across many a situation begging for some Spec# pre and post spec_thumbcondition verification; alas the wait continues. I will attempt to do my part in pushing the call to have Spec# rolled into C# ASAP (V 4.0 pretty please Anders?). Greg Young started this push to have Spec# taken seriously as something that we want to see in the language soon and have it move its way out of research and into product roadmap. Here again is the bumper sticker that Greg made available.

Share/Save/Bookmark

Categories: C#, Spec# Tags: ,

GOF Series: Episode #2 [The Abstract Factory]

August 7th, 2008 Simon Segal No comments

The pattern a day keeps the doctor away series continues. In the last instalment of the series we looked at the Factory Method pattern, this time we look at the Abstract Factory Pattern. The abstract Factory Pattern is useful in creating groups of related object types without a requirement to create their concrete types explicitly and achieves this by using composition where a class delegates the role of object instantiation to another class. This pattern can be described in UML like this:

Click to see in full size

The tests included (as per below) are for the purpose of demonstrating the code and are not meant to be taken as complete unit tests.

   1:  [Test]
   2:  public void AbstractFactoryTest()
   3:  {
   4:      //set an earlier time to that 
   5:      //when the document is created
   6:      DateTime earlier = 
   7:          DateTime.Now.Subtract(new TimeSpan(0, 1, 0));
   8:      //create the mock of the AncillaryService
   9:      var mock = 
  10:          new Mock<AncillaryService>(new 
  11:              LitigationSupportFactory());
  12:      mock.Object.
  13:          SetupProject("My Test Lit Support Project");
  14:      //use the factory method that create a new document
  15:      //using the mock instance object.
  16:      Document litDoc = 
  17:          mock.Object.
  18:          NewDocument("Lit Support Test Document");
  19:      mock.Object.
  20:          PersistDocument(litDoc);
  21:      //perform the tests for 
  22:      //the Lit support factory
  23:      //and the client (AncillaryService) 
  24:      //that has it in its composite.
  25:      Assert.IsTrue(litDoc is LitigationSupportDocument);
  26:      Assert.IsTrue(litDoc.Name == "Lit Support Test Document");
  27:      Assert.That(litDoc.DateCreated.Value > earlier);
  28:      Assert.IsTrue(File.Exists
  29:          (@"C:\DevFileDrop\Lit Support Test Document.litdoc"));
  30:   
  31:      mock = 
  32:          new Mock<AncillaryService>(
  33:              new ImageWorkflowFactory());
  34:      mock.Object.SetupProject("My Test IW Project");
  35:      ImageWorkflowDocument iwDoc = 
  36:          mock.Object.
  37:          NewDocument("IW Test Document") 
  38:          as ImageWorkflowDocument;
  39:      mock.Object.PersistAll();
  40:      Assert.IsTrue(iwDoc != null);
  41:      Assert.IsTrue(iwDoc.Name == "IW Test Document");
  42:      Assert.That(iwDoc.DateCreated.Value > earlier);
  43:      Assert.IsTrue(File.Exists
  44:          (@"C:\DevFileDrop\IW Test Document.iwdoc"));
  45:  }

The code above assumes the AncillaryService, LitigationSupportFactory and ImageWorkflowFactory classes (which are indeed in the download code. The link to the FULL example code can be found here and comes with all previous modules in the series and the accompanying power point presentation to explain each pattern in detail, so I wont repeat that content here.

Share/Save/Bookmark

The future of LINQ To SQL and showing some support.

July 30th, 2008 Simon Segal 3 comments

Recently Ian Cooper posted about his fear that the long term prospects of LINQ To SQL may be diminished and damaged by the volume of effort going into the EF and the fact that the Data Programmability Team are now charged with the future of both products (a race for which would see L2S loose).

I suggested a bumper sticker to help promote the need to maintain and grow LINQ To SQL where it is already providing a real alternative to those who want to practice OO, POCO, PI, strategies commonly used in TDD / DDD circles. The title of the quest to ensure support and growth of LINQ To SQL carries the title "LINQ 2 SQL - Live long and Prosper".

So thanks to my colleague Tim Alford here it is:

linq_2_sql_hand_small 

Please feel free to support LINQ To SQL by displaying this logo.

Share/Save/Bookmark

Categories: C#, DDD, LINQ To SQL, ORM Tags: , , ,
Creative Commons Attribution-ShareAlike 2.5 Australia
Creative Commons Attribution-ShareAlike 2.5 Australia