Archive

Archive for the ‘Design Tip’ Category

Violet UML Editor

March 2nd, 2010 Frank No comments

I use UML to do quick brain storming and when exploring software. While I’ve not posted many write ups here (grad-school!),  I generally don’t want to invest a lot of time in my UML diagrams and only sometimes do I even want to save them.

Often times, especially lately, I’ve been drawing on a whiteboard that I keep in my office.  I find this to be efficient (even over paper because I’d end up throwing it away).

OO Design & Patterns, 2nd Ed Book CoverIn one of my current grad-school classes, we are using “Object-Oriented Design & Patterns” by Cay S. Horstmann as the class text book. I’ve enjoyed the book and it provides some decent examples. I bring the book up because apparently the author of the book created a UML package called Violet UML. I’ve found this to be the best software based UML brain-storming software I’ve ever found. Here are my reasons:

  • It loads quickly
  • I can efficiently draw diagrams without warnings or complex menus to navigate though.
  • The lack of UML rules enforcement means that I can draw partial diagrams; diagrams that mean nothing out of context.
  • It’s open source
  • So far, its more stable / reliable to ArgoUML

If you are looking for a UML package, I must recommend this. I searched and searched for a UML package a while back and I never came up with this. I looked at everything, no matter what and still never found it. So, if you like it, please spread the word (via your own blog, twitter, facebook, etc). I think it is well done software and worth some attention.

http://violet.sourceforge.net/

ORM patterns which are ‘Invisible to the eye’

February 10th, 2010 Frank No comments

The more I work with design patterns*, the more I come to respect them as a design tool. For grad-school, I’m writing a DVCS and I needed some information on ORM patterns. While I’m not sure if this is a real term, I Googled it and found a great article on Invisible to the eye.

The article can be found at: http://giorgiosironi.blogspot.com/2009/08/10-orm-patterns-components-of-object.html

For my project, I’m mainly interested in the Data Mapper and the Table Data Gateway. Both are patterns from Martin Folwer’s book Patterns of Enterprise Application Architecture.

While I’ve not read the book yet, I think I might… After classes…. Anyway, I mostly wanted to share on the 10 ROM patterns listed at Invisible to the eye.

*If  you’d like a good intro to design patterns, I love Head First Design Patterns

Invisible to the eye

Object Relational Mapping > A ‘Design Pattern’ Solution

April 23rd, 2009 Frank No comments

There has been a lot written about Object Relational Mapping — or ORM but I came up with a design that I intend to apply to my own projects and wanted to publish and share the idea.

This idea was my own; when I wrote this I hadn’t seen this idea published elsewhere. However, the idea is derived from a set of very common design patterns. It would not surprise me in the least if another designer/developer already implemented a similar idea. However, I digress…

Preliminary Information

The ORM is a method to take data stored in a relational database-type structure and represent the same data as object orientated classes.

I feel that the ten thousand foot level the idea is straight-forward. Assume that we are using the MVC (Model-View-Controller) design pattern for your application. Furthermore, lets assume that we’ve got a simple object to which will represent our Model (part of the MVC).

Lets assume our model object is the following:

Data Model Example

Data Model Example

The idea is to take a mix of the strategy and the decorator pattern. The strategy pattern is a design pattern that allows you to define the interface for an algorithm which can be different depending on the implementation.

The idea of the decorator pattern is to simply add responsibility to a class (through inheritance). My ORM is a combination of the two patterns.

The Design – a Class Diagram

The pattern is simple.

Diagram with OR Design

Diagram with OR Design

We use the interface to represent the ability to write out or read in with the Encoder. You’d implement the interface on to a derived class of the target class.

Why do we implement this interface on a derived class? Strictly speaking, we don’t have to. Though, this is intentional and part of the pattern that I’m trying to describe. This is the part of the strategy pattern working for us. This would allow us to implement different encoders for different types of storage mediums.

This means that we could create a set for SQL server, XML and perhaps a web service if so inclined.

Usage

The usage, I imagine, to be simple. Setup your basic interface and then derive a target class and apply the interface. Implement your interface to write the object and read the object to/from your storage medium.

One point of doing this, is that if a model object contains a collection  or an instances of another model object, you can use this interface to write and retrieve that object.

An Example

In all honesty, I had hoped to put together a simple but working example of this. I’ve not had the time and I’ve been sitting on this post for a while. I wanted to get this post out. I still hope to get together a simple example but for the time being the description is all I’m posting.

If you have specific interest in an actual implemention of my concept here, please leave a message below. The interest will help modivate me to take the time to get something together.

“Windows OOP” vs. “Cocoa MVC”

March 23rd, 2009 Frank No comments

While I don’t agree with the following article that windows developers (the author is looking at .NET, I believe) can’t implement the MVC design pattern, I do agree with the article that MVC is probably a better way to implement one’s interface. I want to direct your attention to the following article.

http://www.cimgf.com/2008/07/29/cocoa-tutorial-windows-oop-vs-cocoa-mvc/

9 Examples » Fast and Responsive UI (Link)

February 3rd, 2009 Frank 2 comments

One thing I’ve yet to really learn is how to make a well designed responsive user interface in .NET (or any other language).

I came across this article and I thought I’d share it (and save it here for myself). I’ve yet to delve in to Graham’s example but I trust it will be valuable and hence I’m posting it here.

9 Examples of creating a fast and responsive UI with multi-threadinghttp://goneale.wordpress.com/2009/01/27/9-examples-of-creating-a-fast-and-responsive-ui-with-multi-threading/

Graham’s article also points us to another interesting article; an article he recommends: Give Your .NET-based Application a Fast and Responsive UI with Multiple Threadshttp://msdn.microsoft.com/en-us/magazine/cc300429.aspx

Categories: .Net, Design Tip, Multi-Threading, Tips Tags:

@@SERVERNAME

January 20th, 2009 Frank No comments

I was working on a SQL Server project and came across a piece of code that I wanted to only execute if the code was running in production. This is a fairly common problem — code that should only execute if on a specific environment.

Most of the time in my career, I’ve seen people just comment out the code in a given environment. [And yes, I've seen bad mistakes with this method.] While this has obvious potential side effects I didn’t have time to give it much thought… Until recently.

I realized that SQL Server 2000 has a system variable called @@ServerName that will always give you the server name for the active connection.

Using this system variable, you can write some very simple code that will only execute other code in a given environment.

How can you use the variable?

Usage of the system variable (and any system variable) is easy. You can use either Select, Print or any logical statements (such as If or While loops).

All of the following are validate:

1
2
3
4
5
SELECT @@ServerName
PRINT @@ServerName

IF @@Servername = 'Me' BEGIN
END

How to Implement It

How I implemented it was a bit unique; I will first start with a very simple example.

1
2
3
4
5
6
7
Exec ValidateData

IF @@ServerName = 'ProductionSrvr' BEGIN
    UPDATE Users
    SET Processed = 1
    WHERE UserID = @UserID
END

To quickly walk though this code, it is executeing a stored procedure call ValidateData and then we check the @@ServerName variable to find if it matches “ProductionSrvr”. If @@ServerName does, it will execute the update; otherwise the code would go right over the if. This would be great if you didn’t want to update the Users table in the staging or development environments but you did in production.

My twist on implementation

My primary employer does a thing where they lease their servers (and desktop stations) from a provider. The leases expire every 4 years. This means that every four years we migrate databases and web servers to new machines (or virtual machines, as of recent). To my knowledge, we have hundreds of Servers, serving all sorts of software and information (Web sites, databases, Cubes, etc)

Since our SQL Servers are no exception, I wanted to be prepared for such a switch but I still wanted to implement this because of it’s obvious benefits.

I obviously didn’t want to do a find and replace on all of my Stored Procedures and DTS packages (don’t ask) and so I used a function to check the @@ServerName variable against. The function was simple and an example definition follows:

1
2
3
4
5
6
CREATE FUNCTION dbo.fn_ExampleServer ()
RETURNS VARCHAR(100)
AS
BEGIN
    RETURN 'ExampleServer' --Simply return a constant with the server's name
END

My @@ServerName example above would simply become:

1
2
3
4
5
6
7
EXEC ValidateData

IF @@ServerName = dbo.fn_ExampleServer() BEGIN
    UPDATE Users
    SET Processed = 1
    WHERE UserID = @UserID
END

That’s it! I hope others will find this useful.