DevPinoy.org
A Filipino Developers Community
   
Architechture 101: Skill Test Part 1

Lets see if there are some architechture people around here :)

Looking at code below... scrutinize this class and tell me whats wrong with its structure... what design pattern closely resembles it.. and how you can improve it? the code is provided in both C# and VB.NET so that it would be easier for those people who prefer {} and non-case sensitivity to look at it!

[C# Version]

public class Client
{
   private string _name = string.Empty;
   private string _email = string.Empty;
   private string _company = string.Empty;

   public string Name
   {
      get
      {
         return _name;
      }
      set
      {
         _name = value;
      }
   }

   public string Email
   {
      get
      {
         return _email;
      }
      set
      {
         _email = value;
      }
   }

   public string Company
   {
      get
      {
         return _company;
      }
      set
      {
         _company = value;
      }
   }

   Client()
   {
      this.CreateClient();
   }

   Client(string clientName, string clientEmail, string clientCompany)
   {
      this.CreateClient(clientName, clientEmail, clientCompany);
   }

   private Client CreateClient()
   {
      return this.CreateClient(string.Empty, string.Empty, string.Empty);
   }

   private Client CreateClient(string clientName, string clientEmail, string clientCompany)
   {
      this.Name = clientName;
      this.Company = clientCompany;
      this.Email = clientEmail;
      return this;
   }
}

[VB.NET Version]

Public Class Client
   Private _name As String = String.Empty
   Private _email As String = String.Empty
   Private _company As String = String.Empty

      Public Property Name() As String
         Get
            Return _name
         End Get
         Set(ByVal value As String)
            _name = value
         End Set
      End Property

      Public Property Email() As String
      Get
         Return _email
      End Get
      Set(ByVal value As String)
         _email = value
      End Set
   End Property

   Public Property Company() As String
      Get
         Return _company
      End Get
      Set(ByVal value As String)
         _company = value
      End Set
   End Property

   Sub New()
      Me.CreateClient()
   End Sub

   Sub New(ByVal clientName As String, ByVal clientEmail As String, ByVal clientCompany As String)
      Me.CreateClient(clientName, clientEmail, clientCompany)
   End Sub

   Private Function CreateClient() As Client
      Return Me.CreateClient(String.Empty, String.Empty, String.Empty)
   End Function

   Private Function CreateClient(ByVal clientName As String, ByVal clientEmail As String, ByVal clientCompany As String) As Client
      Me.Name = clientName
      Me.Company = clientCompany
      Me.Email = clientEmail
      Return Me
   End Function

End Class

Any challengers?


Posted 02-07-2006 6:46 AM by keithrull

Comments

cruizer wrote re: Architechture 101: Skill Test Part 1
on 02-07-2006 5:00 PM
hmm...seems to be so much code for so little functionality. i don't get what CreateClient() is for...like it returns "this" and it's private? what's the use?

i think it's trying hard to be a factory method. it's much better to just make CreateClient() a static method and have it perform the new operation inside rather than returning "this" (since "this" isn't present in a static method anyway).

or is this code trying hard to be a singleton? i really couldn't tell. :P
jokiz wrote re: Architechture 101: Skill Test Part 1
on 02-07-2006 5:16 PM
no exposed constructor? is this only used through reflection?
TuldokLambat wrote re: Architechture 101: Skill Test Part 1
on 02-07-2006 7:23 PM
It resembles a singleton albeit no way to instantiate it. The CreateClient methods should be made public. The CreateClient method with params is missing some code that should make the actual instantiation (_client = new Client(); //_client here must be declared as static).
punzie wrote re: Architechture 101: Skill Test Part 1
on 02-08-2006 12:50 AM
I agree that it looks like a confused factory class. Some have suggested here that make an outright factory method out of CreateClient.

The other way to look at it is that CreateClient is intended as an initialization routine (InitClient) that's being confused as a factory method. In this case we just remove the return type, since the return value is not really being used anywhere.
Keith Rull wrote Answers to Skills Test Part 1
on 02-08-2006 2:52 PM
Nice! I guess we do have architecture guys here!

anyway, here's the answer to Skills Test Part 1
Keith Rull wrote Answers to Skills Test Part 1
on 09-14-2006 12:31 PM

Nice! I guess we do have architecture guys here! anyway, here's the answer to Skills Test Part 1

Copyright DevPinoy 2005-2008