Wednesday, November 12, 2003

Software Design Patterns


Partly for my own education and partly to interest anyone who may be reading this blog, I'm going to do a series of posts on software design patterns. I find that describing something so another can understand it improves my own understanding, so I'll begin with the "Gang of Four" Factory Pattern.

Factory Pattern


Basic Description

A Factory is a class (or it can be just a method) that creates objects derived from a common super-class or interface. It is usually used in a situation where you don't want your client class to have to figure out what the specific class of an object is, because it could be of several different types. You create a super-class or interface and code the client to call methods of that super-class or interface. Now you have the problem of how to provide the different objects to the client without the client having to know which class is being created. The answer is to create a factory class that has a method that takes a parameter which it uses to figure out which type of object to return.

Example Code

Here is an example in VB.NET of a factory pattern:
(Note: If large spaces appear between lines of code then widen your browser)

First the factory class. (Note: this could be implemented as a method in the client class rather than as a class.)

Public Class ProcessControllerFactory

Public Shared Function GetController( process As String) As ProcessController
Dim result As ProcessController

Select Case process.ToUpper()
Case "EXTRACT"
result = New ExtractController()
Case "IMPORT"
result = New ImportController()
Case "MATCHING"
result = New MatchingController()
Case "CONFIRMATION"
result = New ConfirmationController()
Case "DISTRIBUTION"
result = New DistributionController()
Case Else
result = Nothing
End Select

Return result
End Function

End Class



The client class gets the process controller it wants like this:

Public Sub Execute( action as String)
'declare the variable using the superclass as the type
Dim processCtrl As ProcessController
'now get the controller
processCtrl = ProcessControllerFactory.GetController(action)
'now call the method common to all classes derived from the superclass
processCtrl.runProcesses()
'other code here
End Sub


If the factory were implemented as a method then "Execute" would look like this:

Public Sub Execute( action as String)
Dim processCtrl As ProcessController
'calls its own method
processCtrl = GetController(action)
processCtrl.runProcesses()
'other code here
End Sub


The classes of the objects produced by the factory look like this:

Public Class ImportController
Inherits ProcessController

Public Overrides Sub runProcesses()
'code goes here
End Sub

End Class


And the super-class of all process controller classes looks like this:

Public MustInherit Class ProcessController

Public Overridable Sub runProcesses()
'default handling code goes here or it could be an abstract method
End Sub

End Class

Resources

Factory pattern example
The Factory Method Design Pattern by Gopalan Suresh Raj
Solve application issues with the factory pattern
Implementing the factory pattern using attributes and activation - C# Programming
The Simple Factory Pattern in C#

Friday, November 07, 2003

Psychiatry USA


I just came across a site that gives the entire strategy used by psychiatry.

It also points out that no physical tests exist to show that any "mental disease" exists. One quote is from the mighty National Institute of Mental Health: "...there is no independent test for ADHD. This is not unique to ADHD, but applies as well to most psychiatric disorders, including other disabling disorders such as schizophrenia..." Click on this link for more quotes on the fact of no tests for mental disorders.

Tuesday, November 04, 2003

Cancellation of the Reagan mini-series


I'm not particularly political, it's not a sport I'm very interested in, I prefer sports like basketball or soccer. I am also not a fan nor a detractor of Ronald Reagan; I took even less interest in politics in the 80's than I do now. But when I heard some of the quotes from the script of "The Reagans" I was angered by this new method of character assassination and abuse of the freedom of speech.

I think the founding fathers must be spinning in their graves at the kind of abuse that passes for freedom of speech these days. Back when the US was founded they knew what freedom of speech meant because for years it had been denied them by a repressive imperial government. If you spoke out of line you ended up in jail or worse. Now we see things like pornography, pirating of copyrights and outright lies defended as "freedom of speech".

Want to know what freedom of speech really is? Then go to North Korea, Iran or China and start speaking out against those repressive regimes. You'll soon get the idea.

But perhaps there is hope for true freedom of speech. The public outcry against the Reagan mini-series was fueled in large part by such non-mainstream media outlets as the Drudge Report and talk radio. Thanks to the Internet, people were able to deluge CBS with complaints to the point where it became clear to the powers-that-be at CBS that this show was going to be a major embarrassment to them, so they pulled the plug.

Another good sign was something I heard on the radio this morning. It was on KNX 1070 in LA, which is a CBS radio station. A reporter was interviewing the TV critic of the LA Times. I thought, "here we go", CBS interviewing a guy from a very left-leaning paper. The outcome seemed obvious. But I was wrong. The interviewer was trying to characterize the pressure on CBS as coming from the famous "great right-wing conspiracy" that was dreamed up during the Clinton era, but the TV critic was having none of it and simply pointed out that a "docu-drama" that was full of lies shouldn't be aired in the first place and that the producers should have made sure it was truthful then no one could have complained about it.

And I think that is the essence of what freedom of speech is all about: TRUTH.

Monday, November 03, 2003

Another Good Blog


My friend Zack, who is studying at Berkley University, has a very interesting blog. He talks about history, science and philosophy in a very enlightening way. I've added a link to his site in my links - click on The Lab.

Friday, October 31, 2003

Excellent Blog


I just discovered that my friend Stan has a blog. It's themed on movie reviews and comments on that world. Very well written and interesting: He calls his blog EQUIVOQUE: noun, an amusing use of an ambiguous word. Check it out and enjoy.

Thursday, October 30, 2003

Great Website


A friend just sent me a link to a great site. It's called DoctorYourself.com. It's a site about natural health and natural remedies.

Since the medical profession not only failed to help my daughter as a baby, but actually made her worse, I've not been to a medical doctor. She had a very severe internal yeast infection - it was so bad you could see the stuff growing in her mouth. The doctor gave her an anti-biotic which was (I later found out) in a solution of sugar. Now, even I knew that yeast loves sugar, but evidently the highly trained and qualified medical doctor didn't. Consequently my daughter got worse.

Luckily a friend referred me to a chiropractor who was also a nutritionist. My daughter's condition was handled by what is called "Alternative Medicine" and it was handled quickly and very successfully.

My viewpoint on "conventional medicine" is that if you are dying from some horrendous accident and sowing up a pumping artery or fixing a broken bone is needed then it can be helpful. But under any other conditions it is more harmful than helpful.

A body runs on food, which contains vitamins, minerals and other substances that it uses to build and repair itself. Seems to me kinda obvious that these should be given a great deal of attention by anyone calling themselves any kind of healer. Well, medical doctors know squat about nutrition which explains why so many Americans have diabetes, heart disease, cancer, etc., etc.

The trouble with vitamins and minerals is that the pharmaceutical companies can't make a fortune out of them so they prevent their use by any means at their disposal.

Anyway, enough venting. Just check out DoctorYourself.com.

Thursday, October 16, 2003

Bend It Like Beckham


My friend Stan sends out emails to a few friends giving them his opinions on movies. I especially liked this one so I thought I'd post it for the world to see.

***

Star Wars proved you could spend a lot of money on a movie and get it back. It ended a drought about 20 years long in which the movie industry was afraid to do that. The result was a rebirth for film.

From the beginning of the movie industry, producers have also known that star power was capable of selling movies. But Lucas put out Star Wars without any really big stars, and took the brass ring. (No, Harrison Ford doesn’t count. He wasn’t a star yet.)

But today, studios and producers fall all over themselves creating SFX (special effects) CGI (Computer Generated Imagery) and even fully animated features that aren’t about a duck and a rabbit ... They also still use the power of big stars to suck in the fans. By the time you have big stars walking on Mars being chased by aliens while dodging ray guns, you are supposed to have a bulletproof concoction that will rake in the dough so fast it’s in the black before it goes to video.

But it doesn’t always work.

So how do you explain movies like My Big Fat Greek Wedding or Bend It Like Beckham? No big stars, no special effects, just competent basic cinematography and relatively unknown competent actors and a wonderful story that makes you realize how great life is and how much you love people...

One thing is still basic: The story has to be good. A good story will sell a film that has neither the biggest effects nor the biggest stars, and a super-production with a bad story can die a sorry death.

Bend It Like Beckham is one of those heart-warming films that has so much of what a good story is all about, nothing else matters. You can’t help getting caught up in this great little tale about a talented young Indian woman in Britain who wants to become a soccer star (that’s "football" to you non-Americans) and endeavors to make it go right in spite of her very traditional Sikh parents who have a much more hide-bound notion of how her life should be and a wicked reaction to the idea of her running around on a field kicking a ball "with her legs showing".

Her partner in crime is actually a pretty big star! But she wasn’t when this movie was made. Keira Knightley was the damsel in distress in the blockbuster Pirates Of The Caribbean. But Beckham came out before Pirates. So it’s like seeing unknown Harrison Ford in Star Wars or unknown Julia Roberts in Mystic Pizza. The entire film was made for 3.5 million dollars - chicken feed by today’s standards, when 75 million is common and 200 million is not unheard of. Big stars bloat the budget by 5-20 million each before you even stop by Kodak to pick up the film. But Beckham has made more than 10 times it’s original investment. After a meek opening weekend of only about $190,000.00, it began to grow by word of mouth, mostly. You can count on the fact there wasn’t a lot of publicity in a 3.5 million-dollar budget.

Like it’s beautiful little star Parminder Nagra, who played the Indian soccer phenom, the film finally "showed its legs" and walked through months of hanging around in the top 20 box office successes while jillion-dollar blockbusters came and went in a few weekends. Now it’s finally gone to video.

If that doesn’t make you want to see the video yourself, then let me add one detail. This is a true "feel good" movie! In my lexicon, that’s a good thing, not a bad one.

Just to clear up your next question, "Beckham" is the name of a current British soccer super-star that is worshipped by the girls, and "Bend It" is a soccer phrase, at least in Britain, that has to do with putting some kind of spin on the ball, as nearly as I can tell. So the phrase "Bend It Like Beckham" is something like a baseball fan saying, "Slam it like Sammy Sosa" or a basketball fan saying, "Dunk It Like Shaq".

Wednesday, October 08, 2003

California Wins


The worst Governor in California history bit the dust yesterday. He wasn't terminated by the new Governator, no he was terminated by the people of the State who are sick to death of him and of the legislature.

A commentator yesterday said that if the recall had also included the legislature then they all would have been kicked out too (Democrats and Republicans), and I think he was right.

I hope the legislature gets the message that the people of California want an end to their anti-business attitude, their irresponsible "it's the economy to blame" excuses, their bungling and their gridlock.

Music Review - Oceanborn by Nightwish


I heard a track from this CD some time ago on an Internet radio station, I think it was ProgRock.com or it could have been ProgRadio.com. Anyway, I liked the track but I didn't pursue it further until a couple of weeks ago I was chatting to a girl I met who is from Hungary. We got onto the subject of music and I told her I liked metal and progressive metal. I was surprised when she said metal was her favorite too because she is in her late teens and (at least in the US) most girls of her age are into the usual hit-radio dross. She mentioned that one band she liked in particular was Nightwish and that the lead singer is a woman who was trained as an opera singer. I recalled the track I'd heard and decided to check out the album.

Well, I'm glad I did. This is an excellent album which I'd describe as melodic metal; very tuneful and lively. The vocals of Tarja certainly demonstrate her classical training and the keyboards of Tuomas give a nice classical vibe.

The band hails from Finland and I read on their website (Nightwish) that Oceanborn was their first album. If this is their first album then I'm going out to get more because they rock.

NightWish: Oceanborn

Tuesday, October 07, 2003

California Election


Well, it ain't over 'til the fat lady sings, but if the people I know are representative of the feeling in California today then I think Davis is out and Arnold the Governator is in.

There are a lot of pissed-off people here right now. They are sick to death of the kind of smear politics being practiced by the re-elect Davis newsletter, sometimes known as the LA Times.

The Gloria Alred 11th hour fiasco was just another demonstration of how extreme such people will go to retain power and to slime their biggest rival. Trotting out a woman with a 30 page long criminal record of prostitution and drugs, so she could accuse Schwarzenegger was pretty blatant. I guess Gloria and the accuser were rather surprised when within a couple of hours two people who were actually there come out and told the truth - Schwarzenegger wasn't even there.

Possibly the cancelled subscriptions to the LA Slimes will have an effect, but probably not. The kind of people who would run this kind of campaign care only for power and they "know" that they are "right."