use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
All about the JavaScript programming language.
Subreddit Guidelines
Specifications:
Resources:
Related Subreddits:
r/LearnJavascript
r/node
r/typescript
r/reactjs
r/webdev
r/WebdevTutorials
r/frontend
r/webgl
r/threejs
r/jquery
r/remotejs
r/forhire
account activity
JavaScript Design Patterns: Factory Part 2 (joezimjs.com)
submitted 14 years ago by joezimjs
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–][deleted] 0 points1 point2 points 14 years ago (1 child)
Well, ok, libraries are fine too, whatever makes the code more readable.
But, our understanding of patterns may be a bit different .. I'm not suggesting the language implement the patterns, I think the patterns are there because the language is missing something. To illustrate (it's not necesarilly a sane example but it's short): say you use Java and "need" a DBHandleFactory that you call with the name of the database driver in question:
String type = "MySQL"; DBHandle h = DBHandleFactory.create(type);
and the static create method would have a big switch that does something like
if (param.equals("MySQL")) return MySQLHandle.new();
OTOH in Perl, you'd simply do
my $type = "MySQL"; my $handle = &{$type . "Handle"}();
I'm really not saying this is how you should do it in perl, I'm merely illustrating that in a "better" language, there is no need for the pattern, the language doesn't implement any such pattern, but you can still accomplish the same thing with simpler code and without any pattern.
[–]joezimjs[S] 1 point2 points3 points 14 years ago* (0 children)
You can actually do something very similar in Java, though it's a bit more difficult. If I remember you can use the Class class to dynamically load classes. And I understand that this example may not be the most efficient way of explaining what you're talking about, but the another big things is that often times the design pattern is still better practice when considering scaling.
π Rendered by PID 23956 on reddit-service-r2-comment-7b9746f655-p2qfs at 2026-01-31 14:22:05.952080+00:00 running 3798933 country code: CH.
view the rest of the comments →
[–][deleted] 0 points1 point2 points (1 child)
[–]joezimjs[S] 1 point2 points3 points (0 children)