473,395 Members | 1,856 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,395 software developers and data experts.

factories versus libraries

If I have a "factory" that is in this form:

function ma() {
blah;
}
ma.prototype.a = function() {
blah2;
}
var obj = new ma()

and I have a "library" that's of this form:

ma = {
a: function() {
blah2;
},
b: blah;,
}

Is there any advantage using one over the other? I've done a google and
have found out some things about both but I don't have enough
programming theory to make a decision.
Andrew Poulos
Jul 23 '05 #1
2 981


Andrew Poulos wrote:
If I have a "factory" that is in this form:

function ma() {
blah;
}
ma.prototype.a = function() {
blah2;
}
var obj = new ma()

and I have a "library" that's of this form:

ma = {
a: function() {
blah2;
},
b: blah;,
}

Is there any advantage using one over the other?


With the first version you can instantiate as much objects having the
same method a as needed e.g.
var ma1 = new ma();
var ma2 = new ma();
The second version creates exactly one object having a method a. If you
only want one object of that "type" then the second version suffices but
if you want to created several objects of a "type" then the first
version is what you need.
--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 23 '05 #2
> If I have a "factory" that is in this form:

function ma() {
blah;
}
ma.prototype.a = function() {
blah2;
}
var obj = new ma();
What you have there is a constructor.
See http://www.crockford.com/javascript/inheritance.html
and I have a "library" that's of this form:

ma = {
a: function() {
blah2;
},
b: blah;,
}
What you have there is an object made using the object literal notation.
See http://www.crockford.com/javascript/survey.html and http://www.JSON.org
Is there any advantage using one over the other? I've done a google and
have found out some things about both but I don't have enough
programming theory to make a decision.


Which to use depends on how many objects you are going to be producing.
If you need a lot of them, it makes sense to have a constructor. If you
need only one, it makes sense to make a single object.
Jul 23 '05 #3

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

Similar topics

2
by: Robert Ferrell | last post by:
I'm wondering how Python cognoscenti use/implement factory patterns in Python. In my limited C++ experience, one reason to use a factory method is to make it easier to create instances of classes...
3
by: Jeff Louie | last post by:
Well I finally finished a Chapter on the use of Type Based and Interface Based Class Factories in C# at: http://www.geocities.com/jeff_louie/OOP/oop18.htm Happy Holidays, Jeff *** Sent...
1
by: Patrick Stinson | last post by:
I am trying to create a way to register static members of a **class**, not an object, for making an object factory. The main thing I want is to be able to make a call like class MyClass {...
3
by: YUY0x7 | last post by:
I'm writing because I was having a little problem implementing one of the designs suggested in Modern C++ Design. The one I'm talking about is that of the class factory which registers classes...
3
by: Jeff Louie | last post by:
Well I finally finished a Chapter on the use of Type Based and Interface Based Class Factories in C# at: http://www.geocities.com/jeff_louie/OOP/oop18.htm Happy Holidays, Jeff *** Sent...
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...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.