472,328 Members | 1,223 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,328 software developers and data experts.

Creational design patterns

I have been trying to wrap my head around design patterns
in c# and am very new to this.

I do not understand the point of using factories to create
objects. My understanding is that creating factories to
initialise objects has the benifit of allowing you to
easily add classes without modifying the code.

However in saying this, creating new classes usually
requires requiring new input for the constructors when
requires a change to feed the right data into the factory
to use its constructor anyway. Could anyone here
elaborate on my problem?
Regards
Dan
Nov 15 '05 #1
7 1225
Hi,

If your class factory supports the creation of objects that accept
different types of constructor parameter arguments , you may also like
to consider exposing a Create method in your factory that accepts an array
of
generic System.Object objects, which contains the parameters to
initialize your object with.

MyClassFactory.Create(String className, Object[] constructorParams);

When the factory creates the object via reflection, the right
constructor would be invoked based on the type and number of
the parameters passed in constructorParams.

Regards,
Aravind C
<an*******@discussions.microsoft.com> wrote in message
news:0a****************************@phx.gbl...
I have been trying to wrap my head around design patterns
in c# and am very new to this.

I do not understand the point of using factories to create
objects. My understanding is that creating factories to
initialise objects has the benifit of allowing you to
easily add classes without modifying the code.

However in saying this, creating new classes usually
requires requiring new input for the constructors when
requires a change to feed the right data into the factory
to use its constructor anyway. Could anyone here
elaborate on my problem?
Regards
Dan

Nov 15 '05 #2
Hi!
For right using of patterns you need right architecture
and right implementation.
When ou use Factory pattern you can pass as argument any
object that implements any generic interface.
In Factory method u can check what type of this object and
return something expected for this type.
For instance, u pass object implements IEmployee interface.
Within pattern you check something like this:
if (objEmployee is Manager)
-----Original Message-----
I have been trying to wrap my head around design patterns
in c# and am very new to this.

I do not understand the point of using factories to createobjects. My understanding is that creating factories to
initialise objects has the benifit of allowing you to
easily add classes without modifying the code.

However in saying this, creating new classes usually
requires requiring new input for the constructors when
requires a change to feed the right data into the factory
to use its constructor anyway. Could anyone here
elaborate on my problem?
Regards
Dan
.

Nov 15 '05 #3
Hi!
For right using of patterns you need right architecture
and right implementation.
When ou use Factory pattern you can pass as argument any
object that implements any generic interface.
In Factory method u can check what type of this object and
return something expected for this type.
For instance, u pass object implements IEmployee interface.
Within pattern you check something like this:
if (objEmployee is Manager)
<your code here>

I hope it will help u.
Regards
-----Original Message-----
I have been trying to wrap my head around design patterns
in c# and am very new to this.

I do not understand the point of using factories to createobjects. My understanding is that creating factories to
initialise objects has the benifit of allowing you to
easily add classes without modifying the code.

However in saying this, creating new classes usually
requires requiring new input for the constructors when
requires a change to feed the right data into the factory
to use its constructor anyway. Could anyone here
elaborate on my problem?
Regards
Dan
.

Nov 15 '05 #4
My question still remains unanswered. What is the
difference from calling the constructor directly instead
of going through a factory.

Regards
Dan
-----Original Message-----
Hi,

If your class factory supports the creation of objects that acceptdifferent types of constructor parameter arguments , you may also liketo consider exposing a Create method in your factory that accepts an arrayof
generic System.Object objects, which contains the parameters toinitialize your object with.

MyClassFactory.Create(String className, Object[] constructorParams);
When the factory creates the object via reflection, the rightconstructor would be invoked based on the type and number ofthe parameters passed in constructorParams.

Regards,
Aravind C
<an*******@discussions.microsoft.com> wrote in message
news:0a****************************@phx.gbl...
I have been trying to wrap my head around design patterns in c# and am very new to this.

I do not understand the point of using factories to create objects. My understanding is that creating factories to
initialise objects has the benifit of allowing you to
easily add classes without modifying the code.

However in saying this, creating new classes usually
requires requiring new input for the constructors when
requires a change to feed the right data into the factory to use its constructor anyway. Could anyone here
elaborate on my problem?
Regards
Dan

.

Nov 15 '05 #5
Hi Dan... Here is the list from Guy Steele
1) The methods can have unique self documenting names
2) Objects can be reused rather than constructed each time
3) You can return non public subtypes, hiding the implementation,
supporting dynamic registration of a new subtype on the fly. So you may
get back some encryption/decryption service of unknowm implentation on
the fly, as long as the new service supports the base interface methods
eg encrypt, decrypt etc.

Regards,
Jeff
My question still remains unanswered. What is the

difference from calling the constructor directly instead
of going through a factory.<

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 15 '05 #6
Second try at posting. 1) Lets you use self documenting names and
redundant parameter lists. 2) Allows the reuse of existing objects 3)
Allows dynamic instantiation of non public subtypes eg. registering a
new crytography service and returning an instance of the new service
when you only know the interface type. Adding new choices to a menu
item when you only know the supported interface of the menu item.
Regards,
Jeff

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 15 '05 #7
Dan, the factory shields from the underlying implementation. That is to
say, it is classic OO.

Data access is a great example. You can write a factory that returns a
IDbConnection interface and all the code "above" that point never knows or
cares whether that's a SQL Server or OLEDB connection "under the hood".

<an*******@discussions.microsoft.com> wrote in message
news:08****************************@phx.gbl...
My question still remains unanswered. What is the
difference from calling the constructor directly instead
of going through a factory.

Regards
Dan

Nov 15 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Don Vaillancourt | last post by:
Hello all, Over the years as I design more database schemas the more I come up with patterns in database design. The more patterns I recognize...
1
by: Jay | last post by:
The GOF text is widely considered the definitive book on the topic. Design Patterns: Elements of Reusable Object-Oriented Softare, Erich Gamma,...
1
by: Josh28 | last post by:
Hi We are a group of two chaps just out of undergrad, we created a software to automate the use of Design Patterns. We have put it up at Source...
13
by: John Salerno | last post by:
Here are a few I'm considering: Design Patterns Explained : A New Perspective on Object-Oriented Design (2nd Edition) (Software Patterns Series) ...
2
by: Carlo Stonebanks | last post by:
I have the infamous GoF Design Patterns boo - it's been sittin gon my shelf for years. I have a huge reading list and find this book a rather dry...
22
by: Krivenok Dmitry | last post by:
Hello All! I am trying to implement my own Design Patterns Library. I have read the following documentation about Observer Pattern: 1) Design...
5
by: Ludwig Wittgenstein | last post by:
Other than the Design Patterns book, which book(s) is/are the best to learn object-oriented software design/architecture from ?
7
by: =?Utf-8?B?bWF2cmlja18xMDE=?= | last post by:
Hi, I would like to know more about design patterns and specifically using C#. Can any one recommend a good book? Thanks
10
by: vital | last post by:
Hi, I am designing the middle tier of a project. It has 6 classes and microsoft application data access block. The six classes are DBServices,...
0
by: tammygombez | last post by:
Hey fellow JavaFX developers, I'm currently working on a project that involves using a ComboBox in JavaFX, and I've run into a bit of an issue....
0
by: tammygombez | last post by:
Hey everyone! I've been researching gaming laptops lately, and I must say, they can get pretty expensive. However, I've come across some great...
0
better678
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
0
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: CD Tom | last post by:
This happens in runtime 2013 and 2016. When a report is run and then closed a toolbar shows up and the only way to get it to go away is to right...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.