What was the reason to wrap POCO?

Sep 23, 2011 at 8:56 AM
Edited Sep 23, 2011 at 10:40 AM

What was the reason to wrap POCO like DateTime instance (not static members)? Uniformity?

For example ProcessStartInfo contains properties which make magic with Path, Registry, Environment - so its OK to wrap it.

Sep 23, 2011 at 10:48 AM

It is important because interface cannot contain operators like DateTime has.

        public static DateTime operator +(DateTime d, TimeSpan t)  
        public static DateTime operator -(DateTime d, TimeSpan t) 
        public static TimeSpan operator -(DateTime d1, DateTime d2)  
        public static bool operator ==(DateTime d1, DateTime d2)  
        public static bool operator !=(DateTime d1, DateTime d2)
        public static bool operator <(DateTime t1, DateTime t2)
        public static bool operator <=(DateTime t1, DateTime t2) 
        public static bool operator >(DateTime t1, DateTime t2) 
        public static bool operator >=(DateTime t1, DateTime t2)
Sep 26, 2011 at 2:48 PM

The reason to wrap DateTime so you can mock.  For example, let assume that you'are using DateTime.Now in your code.  It's very difficult to write a test when your code is using DateTime.Now because DateTime.Now will change every time you run your test.  By mocking DateTime.Now you can make sure that new DateTimeWrap().Now always return the same value.

Sep 26, 2011 at 2:54 PM
Edited Sep 26, 2011 at 2:55 PM

Wrapping static members is right. I am talking about instance members and DateTime INSTANCE as only data container.

So only IDateTimeWrap should contain only static members and return usual DateTime to my opinion.

Sep 26, 2011 at 2:59 PM

I don't think you can have static members in interfaces.

Sep 26, 2011 at 3:03 PM
Edited Sep 26, 2011 at 3:04 PM

I mean having 2  wraps: IDateTimeWrap and IDateTimeSystem (or similar cases)

And specifically for time - only IDateTimeSystem returning usual DateTime when calling IDateTimeSystem.Now etc

Sep 26, 2011 at 3:06 PM

I probably don't understand something.  Because you cannot have static members in interfaces.  It doesn't matter how you call it.  May be you mean an interface and an abstract class?

Sep 26, 2011 at 3:11 PM
Edited Sep 26, 2011 at 3:12 PM

I mean next...
Bad design:
IDateTimeWrap dateTimeWrap1 = new DateTimeWrap(...);

IDateTimeWrap dateTimeWrap2 = dateTimeWrap2.Now;
IDateTimeWrap dateTimeWrap1 = new DateTimeWrap(...);

IDateTimeSystem dateTimeSystem = new DateTimeSystem();

IDateTimeWrap dateTimeWrap2 = dateTimeSystem.Now;
The best:
DateTime dateTime1 = new DateTime(...);

IDateTimeSystem dateTimeSystem = new DateTimeSystem();

DateTime  dateTime2= dateTimeSystem.Now;
Oct 17, 2011 at 5:11 PM

VersionWrap? What is the reason?