StrataFrame Forum

Generic

http://forum.strataframe.net/Topic19539.aspx

By Chan - 9/19/2008

Hi,

I read an article and found this code.



IPersonFacade Facade = FacadeFactory.CreateFacade();



public interface IPersonFacade : IFacade { }





What does it meant? What is the meaning of ? What is the advantage of doing so?



Thank you
By Greg McGuffey - 9/19/2008

This is referring (I assume) to the facade design pattern. Here are some articles on it:



http://en.wikipedia.org/wiki/Facade_Pattern

http://www.dofactory.com/Patterns/PatternFacade.aspx

http://www.codeproject.com/KB/architecture/csdespat_3.aspx



This is one of the classic GOF design patterns. It's intent is to simply a more complex class to make it easier to use. Hopefully this will be helpful in answering your questions.


By Chan - 9/22/2008

Hi,

Thank you for reply.

I think that is mistake on the code snippet. The bolded part was missing.



IPersonFacade Facade = FacadeFactory.CreateFacade<IPersonFacade>();



public interface IPersonFacade : IFacade<Person> { }




My question is more on usage on Generic in this sample code. What does it meant? What is the pros of doing so? What is the difference compare with "new" statement? Why not using type casting?



Thank you
By Trent L. Taylor - 9/23/2008

Chan,

I am not sure of the extent of your background in regards to Generics, but we use them often.  Now this is not a good place to get into a training session on Generics as this can become quite deep.  However, I highly recommend using Generics in this type of situation because it is all strong-typed and drasticaly reduces and streamlines code.

If you want to see some places within the framework that uses Generics so that you have a point of reference, you can look at the GenericBusinessBindingSource (Custom BBS) which allows you to pass in a BO and then from that point forward all references within that class are typed as that BO.  That would be my recommendation in trying to understand and get started with Generics.  There are also a lot of samples out on the web...but yes...I would definitely use Generics.