Construction
Editor's Choice on CodeProject.com
Submitted by admin on Tue, 07/13/2010 - 15:32My article on Refactoring to the Template Method Design Pattern has been selected as the Editor's Choice on CodeProject.com. Thanks to them for that.
- Login to post comments
Data Storage
Submitted by admin on Sat, 06/19/2010 - 11:59Databases
Oracle Express Edition
Oracle Database 10g Express Edition (Oracle Database XE) is an entry-level, small-footprint database based on the Oracle Database 10g Release 2 code base that's free to develop, deploy, and distribute; fast to download; and simple to administer.
http://www.oracle.com/technology/products/database/xe/index.html
Microsoft SQL Server Express
Free version of Microsoft's SQL Server RDBMS
http://www.microsoft.com/express/Database/
SQLite
Refactoring to Dependency Injection
Submitted by admin on Sat, 05/15/2010 - 13:17The second article on Refactoring to Design Patterns is now available on CodeProject.com. It's a continuation of the previous article, but takes things a step further. In the second article we extract an algorithm into it's own class so that we can use the Strategy and Dependency Injection Patterns.
- Login to post comments
Refactoring to the Template Design Pattern
Submitted by admin on Wed, 05/12/2010 - 17:58The first of a two part article on refactoring to Design Patterns is now available on codeproject.com. The first article takes you from a single routine that is doing too much and shows the problems with trying to maintain it.
It then shows how to rector the code to the Template Method design pattern and demonstrates how new features can be added to the code while improving rather than degrading the quality of the code.
The sample code is in C#
Part two is coming soon and will take things a step further by introducing the Dependency Injection pattern.
Iterate over Enum Members
Submitted by admin on Mon, 01/25/2010 - 11:23When you are dealing with a variable that can have one of a defined set of values, it is preferable to use an Enum to define those values, rather than use a primitive datatype like Integer.
This tip isn't about why Enums are better, it is about how to iterate over the range of valid values for the Enum. For example, given the following Enum:
Private Enum FileOperation
Open = 1
Close = 2
Save = 3
SaveAs = 4
Copy = 5
Move = 6
Delete = 7
End Enum
Convert lists to comma separated strings
Submitted by admin on Wed, 07/15/2009 - 17:24You have a list or even an array of strings. You want to convert it into a single
string with the list items separated by commas.
Once upon a time you would have looped through the array, added the items to the
string with a comma after each one. Then remembered to trim off th comma after the
last item.
Surely there's an easier way. Meet the Join method of String.
Dim theString as String
theString = String.Join(",", theList.ToArray())
Of course if you're dealing with an array you don't need 'ToArray'
Dim theString as String
theString = String.Join(",", theArray)
The separator doesn't have to be a single character, if you like some space between the
items, that will work too.
Dim theString as String
theString = String.Join(", ", theArray)
And the seperator doesn't even have to be a comma, anything will do.
Dim theString as String
theString = String.Join("|", theArray)
Simple.
Use the Browsable Attribute when creating Form properties
Submitted by admin on Wed, 07/15/2009 - 16:17The move towards treating forms as objects in VB is very welcome and very useful,
but there are some things that go on behind the scenes that you need to understand.
You might add a property to your form intending it to be used at runtime,
however if you then inherit from the form to create another form, the properties of
the first form will be available in the Property Window when the inherited form is
open in design mode.
The reason for this is the VB is allowing you to set the properties of the base class
so that the settings can be reflected in the inherited class right there in design mode.
Very useful, but not always what you want.
If a property only makes sense at run time then stop it appearing in the Design Mode
Property Window using the "Browsable" attribute, as follows:
Imports System.ComponentModel
Public Class MyForm
<Browsable(False)> _
Public Property MyProperty() As String
Of course if the property in the base form makes sense in design mode, and you want to see
the affect it has on inherited forms, then leave the property Browsable attribute as True.
Use Predicate Functions with Lists
Submitted by admin on Tue, 07/07/2009 - 20:10Use a predicate function to create a subset of a list. The new list will only contain items that match the function.
Sub Main()
Dim lst As List(Of Integer) = getList()
Dim evens As List(Of Integer) = lst.FindAll(New Predicate(Of Integer)(AddressOf GetEvens))
End Sub
The predicate function is a simple boolean function accepting items of the type in the list.
Private Function GetEvens(ByVal value As Integer) As Boolean
Return value Mod 2 = 0
End Function
For simple predicates a Lambda function can be used.
Sub Main()
Dim lst As List(Of Integer) = getList()
Dim evens As List(Of Integer) = lst.FindAll(Function(value As Integer) value Mod 2 = 0)
End Sub
The same technique's can be used for all of the list Find methods (Find, FindAll, FindIndex, FindLast, FindLastIndex).
The Specification Design Pattern
Submitted by admin on Mon, 04/06/2009 - 11:24I've written a four part series on the Specification Design pattern. The four articles are available now on codeproject.com. The articles take you from an introduction to the pattern to a simple VB.Net implementation and finaly to a reusable Specification class that uses inheritence, generics and Operator Overloading.
Attributes and Value Objects article on eggheadcafe
Submitted by admin on Sun, 11/23/2008 - 02:17My article on modelling attributes using value objects is available on eggheadcafe. It'll take you though the process of modelling a Temperature attribute, starting with a naive implementation and working towards a fully fledged value object.
