Posts

Showing posts with the label design

JavaScript Is A Toy? So C#, Java, PHP, and Python Are!

Image
I wrote a truly big post about this subject ... but it was nervous and not that technical as well. I decided then to simply post this image, hosted in Pam webOS Project page: Think about the right box, it should be the state of the current Web 2.0 Era ... now think who is in charge to maintain the layer between your server application, and the customer ... I am quite sure 90% of cases will be a Web Designer, rather than a Senior skilled JavaScript Developer ... now wonder why if you ask for JavaScript skills plus Photoshop, you will rarely being able to make right profits from your business. JavaScript is not a toy, and "web speaking", is one of the most important programming language your team should know, it's time to stop to underestimate it.

A completely revisited Singleton and Factory design pattern for PHP and JavaScript

Singleton From Wikipedia In software engineering, the singleton pattern is a design pattern that is used to restrict instantiation of a class to one object. This is useful when exactly one object is needed to coordinate actions across the system. Sometimes it is generalized to systems that operate more efficiently when only one or a few objects exist. It is also considered an anti-pattern by some people, who feel that it is often used as a euphemism for global variable Basically, the last point is true. Whatever we think about Singleton, we cannot say that we do not use this pattern to have the same instance, or object, in every place of our application. The most common case scenario, is usually a database object, or a global queue, used as a stack, or something similar, like a template engine instance or a DOM / XML node. The worst thing ever, is that with languages like PHP and JavaScript, the Singleton pattern is really hard to implement correctly. Why bother with a class? In a lot ...

PHP or JavaScript implicit Factory method design pattern

Update Above technique could be used to create an implicit Singleton as well. class Demo { // your unbelievable stuff } function Demo($some, $arg){ static $instance; return isset($instance) ? $instance : ($instance = new Demo($some, $arg)); } Demo(1,2)->doStuff(); Demo(1,2) === Demo(1,2); // true from Wikipedia The factory method pattern is an object-oriented design pattern ... More generally, the term factory method is often used to refer to any method whose main purpose is creation of objects. I have talked about JavaScript possibility different times in my prototypal inheritance documentation, and in other posts of this blog. The summary is that thanks to perfect this behaviour , that for some unknown reason someone would like to modify in JS2 , making them ambiguous when you are using a constructor as a function and not, for example, as private method, we can create intelligent constructors that does not require the usage of new keyword - in a Pythonic way: // Java...