Archive

Posts Tagged ‘Design Patterns’

Yet Another Singleton

January 14th, 2012 No comments

I’ve got an amusing problem at work.  We need to create a way of passing runtime arguments around our app with safe and consistent results.

One solution is create a global class that sits in the core library.  All of the properties would have to be static.  At runtime, the bootstrapper updates the properties then we point everything to the global class when we need to know a value. 

But it smells.  A stinky lit’ hack. 

Read more…

Interface Examples

May 29th, 2011 No comments

(Another snippet I originally posted to CodeKeep.)

Code:


interface IPlural
{
  void Load();
  void Load(ELoadOptions option, int id);
}

interface IMembership
{
  void Save();
  void Delete();
  void Load(int id);
}

Usage:

public class CAddresses : List<CAddress> , IPlural
{
  public void Load()
  {
    // do something
  }

  public void Load(ELoadOptions option, int id)
  {
    // do something
  }
}

Read more…

Tact…

June 4th, 2010 No comments

… is not something I’m known for.  Being an introvert, I’d rather avoid the uncomfortable dialog.  If I can’t avoid it, I want to end it as quickly as possible.  My “normal” method is to lay out my argument as logically as possible.  If that doesn’t work, I go for the throat and attack the inner most issue at hand.  Pulling out the nasty gore and exposing it to daylight, so we can address the core problem and move on as quickly as possible. 

So…

I am struggling with my current client.  The lead is… um challenging.  Let me give you a bit of background. 

Read more…

To Kindle or not to Kindle? That is the question.

May 1st, 2010 No comments

It looks like I’ll be going back into the field when I return from vacation.  Honestly, I’ve run out of tasks to keep me busy at the office and I don’t like make-work tasks.  I don’t mind handing them out to other people ;) , but I hate coming up with things for myself.  I don’t create from scratch.  I solve problems.  Present me with a problem and I’ll find a solution.  That isn’t the same things as someone who can come up with problems we didn’t realize we had and find new solutions.  I’m not the pie-in-the-sky idea man.  I’m more of the grimy fix-it dude. 

Anyway, I like books.  I love books.  This can be a problem.  1) I almost always have one, possibly two, maybe even three reference books in my laptop bag.  Carrying around these books gets very heavy.  Hard on my body when they are strapped to my back.  Hard on my gear.  2) The woman poo-poos my reference book collection.  I have a large rolling cart jamb-packed full of books in the office closet.  I removed the bar for clothes and rolled in my cart.  3) Airlines charge by the pound.  If I don’t take 3 or 4 big books with me, our travel gear would be considerably lighter.  4) Ad-nausuem.

Read more…

One way to manage an ‘OK’ button with WPF / MVVM

November 20th, 2009 1 comment

I am using the M-V-VM pattern on a WPF app. The rules that we are following on my team state that the View only knows about the ViewModel via the DataContext. The ViewModel has no explicit knowledge of the View.

BTW: I created the project using the WPF M-V-VM template available on CodePlex (I think?). It already contains the DelegateCommand classes.

I have an “OK” button.

In WPF, a button does nothing. If you want to do do “something” you have to wire up a command that resides in the ViewModel.

View:

<Button Command="{Binding UserClickedOkButtonCommand}" Content="OK" />

 

ViewModel:

public ICommand UserClickedOkButtonCommand { get { return new DelegateCommand( UserClickedOkButton); } }

public void UserClickedOkButton()
{
// do something
}

 

If you put a break point on the UserClickedOkButton, you will see the event is correctly mapped to the delegate method. So how do I close the View?

It takes a couple extra steps to get all of your ducks in a row.

First, add an x:Name=”ThisWindowName” to your View header.
Second, add a command parameter that refers back to your new window name.
Third, update the Command in the ViewModel to use a Window as it’s argument.
Fourth, use the input window argument to close the window.

Here’s the code.

View:

<Window
	...
	x:Name="ThisWindowName"
>
...
<Button Command="{Binding UserClickedOkButtonCommand}" CommandParameter="{Binding ElementName=ThisWindowName, Path=.}" Content="OK" />

 

ViewModel:

public ICommand UserClickedOkButtonCommand { get { return new DelegateCommand( UserClickedOkButton); } }

public void UserClickedOkButton(Window window)
{
	// Do Something
	window.Close();
}

The window is closed. Concerns are separated. MVVM rules are followed.

Works on my machine.

Good Enough?

September 10th, 2009 No comments

Good Enough

Hi. My name is <withheld> and I have a coding problem. I’m an obsessive/compulsive programmer. For every feature request, I can think of 5, No 10! (so-called) improvements.

You say you need a knife to cut a tomato. I think Swiss Army knife with a saw, scissors, tweezers, multiple screwdrivers, leather reamer (yes I’ve actually used it for its intended purpose), can/bottle openers (including wine) and oh yeah a couple blade that could cut up your boring tomato.

Am I thinking ahead?
Am I simply showing off?
Am I getting my nerd on?
Am I ignoring the needs of my users so I can mentally masturbate?

Is there any real difference in any of these questions?

Let the war in my head begin…
Yes. I mean, No! I’d never do that. Well, maybe I would. But it’s cool.

So how does it end?

How do I find the disciple to develop a widget that is good enough without anything extra?

Read more…

Hanselman Yaks w/ Uncle Bob

July 21st, 2009 No comments

I’ve been listing to the Uncle Bob (Robert Martin) podcasts on Scott Hanselman’s site, http://www.hanselminutes.com/HanselMinutes.com.

Return of…:
http://www.hanselminutes.com/default.aspx?showID=189

SOLID
http://www.hanselminutes.com/default.aspx?showID=163

SOLID: This time with feeling.
http://www.hanselminutes.com/default.aspx?showID=168

Are you an astronaut?

April 21st, 2009 No comments

An architecture astronauts that is?

As I said yesterday, I’m spending some time to studying design patterns. I’m ears deep in research on MVC which has led me to MVP and beyond. I’ve got some nasty code tightly bound to a WinForms UI. I want elegance and flexibility. What I have is neither.

So…

It is time to refactor. Read more…

Recovery

April 20th, 2009 No comments

After a relaxing weekend, I had a terrible night last night. All of the pets are in ‘spring-mode.’ The dog wouldn’t lay down. The kitten was racing through the bedroom and the pushiest of our cats decided that I was paying enough attention to her… at 4 am. Needless to say, I didn’t get much sleep last night. Read more…

Grease under my nails

April 3rd, 2009 No comments

I couldn’t sleep last night. I worked in the garage until after 23:30, then spent time installing new parts on the master bathroom shower. It was after 00:30 when I finally crawled into bed. Then I couldn’t sleep. I read for a while, which didn’t help. I learned about the “Query Pattern” and that got me thinking about some development I’ve been working on for the last couple weeks. I laid in bed ‘thinking’ until about 02 when I got up to play Peggle until 03:30. Read more…