Specifications & Extension Methods
Thursday, March 06, 2008 5:56:27 AM (Mountain Standard Time, UTC-07:00)
Last week I went and checked out JP's latest presentation on Generics at the Calgary .NET User Group, and as usual it was awesome! He's definitely knee deep in C# 3.0, and was dropping lambda's and extension methods like it was old news... Here's some of the stuff I learned.
Extending the ISpecification interface via the use of Extension methods.
public static class SpecificationExtensions {
public static ISpecification< T > And< T >( this ISpecification< T > leftSide, ISpecification< T > rightSide ) {
return new AndSpecification< T >( leftSide, rightSide );
}
public static ISpecification< T > And< T >( this ISpecification< T > left, Predicate< T > criteriaToSatisfy ) {
return left.And( new Specification< T >( criteriaToSatisfy ) );
}
public static ISpecification< T > Or< T >( this ISpecification< T > leftSide, ISpecification< T > rightSide ) {
return new OrSpecification< T >( leftSide, rightSide );
}
public static ISpecification< T > Or< T >( this ISpecification< T > left, Predicate< T > criteriaToSatisfy ) {
return left.Or( new Specification< T >( criteriaToSatisfy ) );
}
private class AndSpecification< T > : ISpecification< T > {
public AndSpecification( ISpecification< T > leftCriteria, ISpecification< T > rightCriteria ) {
this.leftCriteria = leftCriteria;
this.rightCriteria = rightCriteria;
}
public bool IsSatisfiedBy( T item ) {
return leftCriteria.IsSatisfiedBy( item ) && rightCriteria.IsSatisfiedBy( item );
}
private ISpecification< T > leftCriteria;
private ISpecification< T > rightCriteria;
}
private class OrSpecification< T > : ISpecification< T > {
public OrSpecification( ISpecification< T > leftCriteria, ISpecification< T > rightCriteria ) {
this.leftCriteria = leftCriteria;
this.rightCriteria = rightCriteria;
}
public bool IsSatisfiedBy( T item ) {
return leftCriteria.IsSatisfiedBy( item ) || rightCriteria.IsSatisfiedBy( item );
}
private ISpecification< T > leftCriteria;
private ISpecification< T > rightCriteria;
}
}
By accepting a Predicate<T> delegate as the second argument you can now inline your lambdas and still take advantage of specifications. Client components can now take advantage of these extensions like this...
public class SlipsRepository : ISlipsRepository {
public SlipsRepository( ISlipDataMapper mapper ) {
_mapper = mapper;
}
public IEnumerable< ISlip > AllAvailableSlips() {
return _mapper.AllSlips( ).Where( Is.NotLeased( ) );
}
public IEnumerable< ISlip > AllAvailableSlipsFor( IDock dockToFindSlipsOn ) {
return _mapper.AllSlips( ).Where( Is.NotLeased( ).And( Is.On( dockToFindSlipsOn ) ) );
}
private readonly ISlipDataMapper _mapper;
private static class Is {
public static ISpecification< ISlip > NotLeased() {
return new Specification< ISlip >( slip => !slip.IsLeased( ) );
}
public static Predicate< ISlip > On( IDock dock ) {
return slip => dock.Equals( slip.Dock( ) );
}
}
}
The base specification class becomes a quick and easy...
public class Specification< T > : ISpecification< T > {
public Specification( Predicate< T > criteriaToSatisfy ) {
_criteriaToSatisfy = criteriaToSatisfy;
}
public bool IsSatisfiedBy( T item ) {
return _criteriaToSatisfy( item );
}
private readonly Predicate< T > _criteriaToSatisfy;
}
Justice Gray For MVP
Monday, January 07, 2008 10:20:46 PM (Mountain Standard Time, UTC-07:00)
I nominate Justice Gray for the Microsoft MVP Award.
I think it's time! Don't you?
Photo's From The Nothin But .NET Boot Camp
Monday, November 12, 2007 9:39:33 PM (Mountain Standard Time, UTC-07:00)
Along with the collection of photos, (Thank you Mr. Clement), I suggest you check out Sean and Adams' notes on the week long boot camp. Follow the links below:
Adam:
Sean:
To find out more about the intense week long boot camp check out JP's site.
A Moment To Reflect
Thursday, October 25, 2007 6:25:14 AM (Mountain Standard Time, UTC-07:00)
This post is a little over due, but it's been on my mind. I realize these days that I'm spending more time trying to think of good posts rather then just writing out posts. I'm not sure which style I favor. I find it actually helpful to flush out ideas from my head on a daily basis so that I can clear my mind and move on.
To the point... last weekend at the Edmonton Code Camp was awesome! I'm not sure how else to describe it... Up in Edmonton I got the sense that the members of the Edmonton .NET User Group truly understand the concept of "community". It truly felt like a "community." I met so many passionate software dev's that really cared about helping the community grow and get better. It seemed like everyone had the same goal and was working towards that.
I had the great privilege of meeting Mr. Justice Gray in person, who not only bought me lunch but introduced me to several of his peers. He gave me some very helpful advice to guide me in my career. The great knowledge learned from his shared experience is invaluable. Thank you for making me feel at home Mr. Justice!
Earlier in the week I had been spiking how to automate a click once deployment using NAnt and came across this post by Mr. Neil Bourgeois. Coincidentally Mr. Neil just so happened to be at the Edmonton Code Camp, and also gave a presentation. I was taken back by how kind and humble he acted. When I found out he was an ex-thought worker, I was immediately froze up in fear. Why? I don't know... He was just very genuinely caring and seemed to want to help further if he could. I surely hope that I can be as humble as he, when I'm that talented!
Mr. Anand, was very quiet much like myself. He seemed very thoughtful and it was interesting to see the relationship between him and Justice. They seem to genuinely care about each others as peers. I sure hope to get to know you better in the future good sir!
It was kind of cool when I bumped in to Steven Rockarts and he knew my name. Kind of weird, but I imagine he must feel the same way. It's great how you can get a feel for people by reading their writing, and blogging tends to make it much easier to connect with people.
I feel like I'm name dropping here a bit, so I will wrap this up. I really enjoyed my day at the Edmonton Code Camp, I found the presentations very informative and found the hallway chats even more amusing. It's great to see that a .NET community can come together the way the Edmug one has. Hopefully as a group we can start to shift the way that software is built here in Alberta.
Alberta Architect Forum
Saturday, September 29, 2007 7:18:41 AM (Mountain Standard Time, UTC-07:00)
Mr. Bill Simser just posted about the "Alberta Architect Forum" on Monday, October. 01, 2007.
It sounds like fun, some of the speakers are:
It's to bad that it's full, and I didn't find out until now, otherwise I might have begged my manager to let me go!
Bringing the Power of the .NET Framework to Your Existing Application
Thursday, September 27, 2007 6:07:08 AM (Mountain Standard Time, UTC-07:00)
Just a quick reminder but tonight is John Bristowe's presentation on "Bringing the Power of the .NET Framework to your existing application".
Bringing the Power of the .NET Framework to your existing application.
Thursday, September 27, 2007
5:30pm - 7:30pm
Nexen Conference Center Theatre
Plus 15 Level
801 - 7th Ave SW
Calgary, AB
This should be a great topic for all you VB6 nuts out there.
For more info...
Volunteering at the Calgary .NET User Group
Monday, September 03, 2007 1:06:18 PM (Mountain Standard Time, UTC-07:00)
So it's been a pretty laid back weekend at our house. So far Alli and I have watched quite a few movies, a few more then I really care to admit. It's definitely been worth it though, the calculated down time was just what I needed.
On Friday, I put in my first couple of hours volunteering at the Calgary .NET User Group. At the last presentation I offered to volunteer for the upcoming Alberta Tech Fest and I received an email from Daniel about meeting at 5:00pm Friday evening. So I made my way to the EUB and met the Calgary .NET User Group Executive committee. Apparently, there's been quite a bit of turnover lately and it's been difficult finding volunteers. I was one of 5 people that evening who offered to volunteer, but was the only one to show up for the meeting. I can't say that I blame any of the others, we only received an email the morning of the meeting and it was at 5:00pm on a Friday evening before the start of the long weekend.
So a few things were covered in the 2 hour meeting, A few dates were changed for upcoming events but here's what I learned:
It looks like October should be a busy month!
Calgary .NET User Group Silverlight Presentation
Thursday, August 30, 2007 5:41:01 AM (Mountain Standard Time, UTC-07:00)
Good morning! Last nights presentation on Silverlight at the Calgary .NET User Group was pretty darn good. There are still quite a few things that need to get worked out in the beta for Visual Studio 2008, but it was cool to see it in use. The experience in it doesn't seem all that different then Visual Studio 2005 except that you can target different versions of the .NET Framework. You can create Silverlight projects and some other goodness.
I realized last night that I had made a bit of a mistake, when filling out the evaluation I marked 5's for most of the items assuming that 5 was a good thing. Just before handing in my evaluation I re-read it to see that...
1 = Strongly Agree 5 = Strongly Disagree
Ahhh.... Who made 5 Strongly Agree? I think I've been giving presenters really bad marks without even knowing it. I must come across as a jerk! So to all the presenters who received a bad mark from me at one of the Calgary .NET user group meetings, my bad! The marks are backwards!
Oh boy... that means this year I probably accidentally gave bad marks too James Kovacs, Richard Cambell, John Bristowe and a bunch of presenters at the Calgary code camp. Sorry guys, but honestly... who makes 5 a bad mark and 1 a good mark. Doesn't it make more sense to have it the other way around?
Last night Daniel also announced that on September 29th, 2007 we will be having the Alberta Tech Fest 2007 which will be a day of presentations for developers, architects and IT pro. Sounds interesting hopefully it happens...
Silverlight Presentation
Wednesday, August 29, 2007 5:10:08 AM (Mountain Standard Time, UTC-07:00)
Good Morning! It has now been a week since my last course has ended and I think life is just starting to go back to normal (whatever that means!) I've been working full time and going to school part time from January till now. And although I've had days where I felt sluggish, none have been like that last few. I don't know why it is, but it wasn't until after school end did it hit me how fast this year has gone by. Anyway's I have one more course to go, but that doesn't start until October.
Tonight I'm off to go check out John Bristowe's presentation on Microsoft Silverlight at the Calgary .NET User Group. The presentation will be an introduction to Silverlight and a demonstration on building an ASP.NET application using Silverlight. Should be interesting, if you're interested go check out the Calgary .NET User Group. Or just show up at...
Wednesday, August. 29, 2007
5:00pm - 8:00pm
Nexen Conference Center Theatre
801 7th Ave SW
Calgary, AB, Canada
That's all for today. GET BACK TO WORK!
The Suburban Ghetto Cowboy
Friday, June 08, 2007 7:24:00 AM (Mountain Standard Time, UTC-07:00)
Good Morning! Well yesterday was a super loooong day for myself! I walked out the door at 7am and walked back in at 10:31pm. Beat that!
After work i went and checked out John Bristowe's presentation on Windows Workflow at the .NET User Group. We even got an extra presentation on ASP.NET Futures, Visual Studio 2008 , Dynamic data controls and a brief discussion on the DLR. Pretty cool stuff!
So I learned that a completely different crowd rides my bus late at night. It was weird... I walked to my regular stop and caught my regular bus at 9:30ish last night. The first thing I noticed when i step on, was the overwhelming smell of urine. Ugh... so i start looking down and at all the seats... where is it? I don't want to step in it, or sit in it, where is it coming from. I never found it.
Also, it was battle of the bands on the bus. I was trying to read a book, but I just couldn't. There were so many people with mp3 players all playing different types of music, and each one trying to play their music louder then everyone else. Where was I? Where did you guys come from? How come I never see you guys during the day? ... ahh... livin' in the suburban ghetto!
Have a good weekend!
Bueller... Anyone? Anyone? Anyone?
Thursday, July 28, 2005 5:47:21 AM (Mountain Standard Time, UTC-07:00)
Well well well… one more day to go. Ok so last night after work I went home for about 15 mins then I left to go to the .net user group meeting at the UofC. When I got there the pizza 73 guy was just leaving. They ordered 10 pizzas. Mmmm… pizza. So I munched and waited for my other co-workers to show up.
The presenter was John Bristoe a Microsoft Regional Director. And the topic was web services. The first 2 hours were on 10 tips on using web services and the 2nd 2 hours were on changes to web services in visual studio 2005.
whoa… Mr. John sure knew his stuff, but I had no idea what he was talking about. He used every acronym in the book, and I really had no idea what they stood for. I think the highlight of the 4 hours was the pizza, oh and I got another Microsoft pen to add to the collection. If I had some sort of experience working with web services then I’m sure the presentation would have been helpful, but for my background, it was waaaaay to deep for this guy.
I’m looking forward to the next presentation with Dan Sellers. I enjoyed his presentation on master pages and I found him easier to follow. Power point slides really, really, really bore me. However Mr. John was a little more animated in the way he presented overall. He is a little hard to approach although, just because… well I guess it goes back to the fear of asking a stupid question. The way he would almost be sarchastic in his response to some of the questions. Like an underlying tone, “are you kidding me? How you could you not know? What are you talking about? That’s what I said buddy!”
Anyways I’ve probably critiqued the presentation enough, but that’s my point of view. Now I just have one day to go and I’m on my way to a 4 day weekend… woo hooo… so have a great weekend and I’ll see you on Tuesday!
C'mon GET TO WORK!
A whole lot of ranting, with very little substance.
Thursday, June 30, 2005 5:51:21 AM (Mountain Standard Time, UTC-07:00)
Good Morning... mO so tired~! ... so I was at work until about 5:30 pm last night, it's an hour later then the time i usually leave. meh... no biggie. except the .net user group meeting started at 6:15pm. Eeep... Needless to say I'm a weeee bit sluggish this morning. The UG meeting was really good. I really enjoyed the presentation on using Master Pages, Themes and Navigation. Suuuupeeerb, I can't wait to use all of these items. Hopefully, I will find some free time tonight to give 'er a try. Thanks Mr. Dan Sellers for the Presentation!
Well, it's looking like it's going to be a beautiful day. I find it interesting just how empty the office is when I get in to work in the morning. I get to see who's actually showing up on time, and who's leaving when they're supposed to be. I technically don't start until 8am, but I usually make it in around 7:40ish... enough time for me to post a single blog entry. It's interesting to see what time the 7:30 starters actually get to work, then see them leave a half hour before me. I really need to let loose and not be just a hardass. I'm sorry, a little anal retentive like that. Time is a big part of my life.
Anyways, I feel like I haven't had any personal time for a while now. I guess this is what it feels like to be an
'adult' hey? Although I'm 21, I feel like I havent really hit adulthood until recently. Man, high school sure is looking much better these day. All that free time, and I spent most of it doing a whole lot of nothing. Time well wasted in my opinion. Geeebus, my thought's are all over the place today.
You know, I've heard a little talk around the office about starting your own business and risks in doing so. And how a lot prefer to work for someone else. Let someone else take the risk. Hmmm... I honestly don't feel the same way. The other day when I was talking to myself, *you heard me*, I said "I've never done anything right in my life, without doing it wrong first." And I think that's kind of my personal philosofphy, I'm not afraid to to take chances, I've made a lot of mistakes but, hey, I've rebounded. I've learned to pick my sorry butt off the ground. What the hell am I getting at here? I guess what I'm trying to say is... well.. I'm a terrible employee, I'm opinionated, I think out of the box, and I want to be my own boss. But I realize in order for me to become a good boss, even if my only employee is me, I have a lot of skill to learn. And until then, I guess I'll be sitting here in my cubicle feeding the corporate monster. I just hope he's hungry, because I've got a lot to learn!
Have a great day, and enjoy the long weekend~! (That goes for both sides of the border)
Peace,
- Chili K.
What a great week~!
Wednesday, June 08, 2005 5:53:14 AM (Mountain Standard Time, UTC-07:00)
Good morning... well the rain seems to have stopped. but every single little town around Calgary seems to be under a evacuation alert. there's flooding going on all over i guess. not on my block though... hehe suckers~! but really that must suck... how do you deal with your home getting flooded. I wouldnt be able to take it... I would want to move. meh~! To all of you affected by the flooding... good luck~!
Well, yesterday afternoon I took off to an MSDN/Technet presentation with some co-workers. It was pretty damn sweet~! It was a fast track seminar on Visual Studio 2005 Team
Suite. Hot damn homie... and we all got a copy of the beta addition to take home. As well as SQL Server 2005 with a 365 day license and bunch of other goodies. This was my first Microsoft seminar of any sort and man it was fun. The presentation was 'FUN'... yes you heard me... less powerpoint more presentation. There were a couple of presenters and I would refer to them as Fred Flintstone and Barny Rubble. They worked so well together, it made the presentation funny and interesting. Not to mention the free XBOX lottery and Hacky Sacks... and Hats etc. Thanks Microsoft, Barnaby, Derek... and uh oh I don't remember the other presenters name. I'll look them up and make sure to throw you some links to their blog. Greaaaat stuff~!
So in my night class last night I learned a new way of designing a page layout in Photoshop. It was more of a sneak peak then a lesson but I think I got the jist of it... now if I can just adopt this new found language in my assignment. WHICH SUCKS A**~! Ok so what's the use of being the greatest developer in the planet if your site looks like crap. (I'm not referring to myself as the best developer, I'm far from it. I'm just trying to make a point.) My hat goes off to all of you crazy web designers. It takes a lot of creativity to put out some of the great sites that you do. So why don't you toss me a trick or two... maybe even refer me to some where I might be able to get some ideas for page designs. Hook a brotha up...
And it's wednesday, oh did i mention the trip to mexico in september is booked? Saturday, September. 17. 8:45am... woo hooo... "
i'm so excited, and i just cant fight..."