Home  /  Questions  /  Question

53   94.5
Aug 02, 2010

Does this code follow the Factory Design Pattern?

I am somewhat confused about Factory Pattern. Please review this code . When we need object of KeepItems we will instantiate KeepItemsConcrete Class. Is this pattern a Factory Pattern?


Interface IKeep 
End Interface

Public Class KeepItems 

private itemNumber As Integer
private itemName as String

public sub New() 


End Sub

public Function GetItemDesc() As String

Return itemName & itemNumber.ToString() 

End Function

End Class

Public Class KeepItemsConcrete 
 Inherits KeepItems 
   Implements IKeep 

End Class


100   96.6
Aug 03, 2010
In your example, the interface is empty, your child class has not modified the parent class which makes it redundant. So this would be a completely wrong example for any design pattern.

Simply put, Factory pattern is all about having a Factory class which has a method to create a Product class you want i.e. you create create a factory producing the desired product. Here's a link having simple example in case the one here are inadequate: http://wiki.asp.net/page.aspx/310/factory/
 1 comment
Suppose different related classes don't have common methods ,then in that case method prototype declaration in interface will create problem .Is it necessary to declare methods in Interface ? --- Shyam Kumar  Aug 03, 2010

588   99.9
Aug 03, 2010
I created a working example that might help.  It's a simple logging object for your applications that allows you to choose where the logs are being written to, either a Text file, database or email.

Although I'm still fairly new to Design Patterns, I'm a little torn between whether my example would be considered more a Strategy Pattern than a Factory Pattern.

You can read about the application here: http://www.kingwilder.com/Blog/tabid/55/EntryId/29/ASP-NET-Simple-Logger.aspx

And download the sample application here: http://www.kingwilder.com/Downloads/tabid/56/Default.aspx

I hope this helps.


King Wilder
MVC Central