473,387 Members | 1,530 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 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 1270
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 the more I want to try to design some kind of...
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, Richard Helm, Ralph Johnson, John Vlissides ...
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 Forge--http://dpatoolkit.sourceforge.net/ The...
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) by Alan Shalloway Design Patterns C# by...
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 read and am always putting it off. I have...
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 Patterns by GoF Classic description of Observer....
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, Logger, ProjectServices ... etc. and all these...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.