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

Are classloaders good for Factory methods?

Is it a good idea using classloaders in Factory methods or builders to
select the class to instantanate? Something *like*:

class Factory {
private Classloader ldr = Factory.class.getClassLoader();
AnInterface getAnObject(String classname) {
if (isClassNameValid(classname)) {
Class cls = ldr.loadClass(classname);
return (AnInterface)(cls.newInstance());
} else {
throw new AppropiateException();
} // end else
} // end function
} // end class

Of course, there's more than that needed (even to compile). But is the
general pattern a good idea? Are there any pitfalls or warnings
involved with that kind of design?

--
Jimmy Cerra
http://nemo.dev.java.net

] ===========================================
] "my mind is slipping away...
] ...day by glorious day"
] Robin Gorkin
] ===========================================
Jul 17 '05 #1
0 1168

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

Similar topics

17
by: Medi Montaseri | last post by:
Hi, Given a collection of similar but not exact entities (or products) Toyota, Ford, Buick, etc; I am contemplating using the Abstraction pattern to provide a common interface to these products....
7
by: Aman | last post by:
why should factory methods be virtual in C++ ? what would be the impact if they were not ? -- Posted via Mailgate.ORG Server - http://www.Mailgate.ORG
6
by: Boogie El Aceitoso | last post by:
Hi, I'd like to have a function factory that returns objects of a class hierarchy. What's the best way to deal with the fact that different subclasses will have different constructor arguments?...
3
by: Sebastian Faust | last post by:
Hi, I am currently reading the chapter about abstract factorys from "Modern C++ Design" and wondering how it would be possible to create an object which has a constructor with parameters. At the...
10
by: Chris Croughton | last post by:
What do people call their factory functions? 'new' is not an option (yes, it can be overloaded but has to return void*). The context is: class MyClass { public: // Factory functions...
3
by: Rob Thomas | last post by:
Hi, I'm just getting started with real OO design and programming and am after a little advice. Basically, I've got a Customer class and an Agency class. The Agency class inherits all the...
6
by: BBM | last post by:
I have an object that has a fairly complex construction sequence, so I have written a dedicated "factory" class that invokes the constructor of my object class (which does nothing but instantiate...
2
by: Julia | last post by:
Hi, I have an application composed from layers like the following A --B ---C A is the top layer C uses an Abstract Factory to Create Concrete classes
2
by: DotNetGuy | last post by:
I have developed a data access layer in my web site application by using web client software factory and put it in my business module as a service. The question is: Is it a good option to reuse...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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.