<br><br><div class="gmail_quote">On Sat, Sep 15, 2012 at 12:32 PM, Chanaka Dharmarathna <span dir="ltr"><<a href="mailto:pe.chanaka.ck@gmail.com" target="_blank">pe.chanaka.ck@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hi,<br><br><div class="gmail_quote"><div class="im"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div>
>> I stumbled upon this piece of code (random pick) :<br>
>><br>
>> PMA_CommonFunctions::getInstance()->backquote($_REQUEST['view']['name'])<br>
>><br>
>> and it made me wonder if using a singleton for PMA_CommonFunctions is<br>
>> necessary, because basicaly PMA_Commonfunctions is a collection of<br>
>> methods, not really a 'living' object.<br>
>> So then I had a look at the class, and I discovered that the class has<br>
>> no class variables (apart from the _instance variable) and an empty<br>
>> constructor.<br></div></div></blockquote></div><div><br>Exactly, that class has no properties except _instance which needed for implement this pattern for refer to the class instance itself. So this is not a living object.<br>
<br>I search bit more in this kind of cases and get to know that, this kind of utility classes are making static. And it is faster than singleton class. From the both approaches our work can be done. But not the exact need for use singleton pattern here.<br>
</div><div class="im"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div><div>
>> So basicly this should be a static class, with static methods, because<br>
>> no instance is needed for it to work.<br>
>><br>
>> And the above piece of code will become :<br>
>><br>
>> PMA_CommonFunctions::backquote($_REQUEST['view']['name'])<br>
>><br>
>> BTW: If you convert it to a static class, don't forget to replace the<br>
>> $this->method() calls by the static equivalent self::method().<br></div></div></blockquote></div></div><br>I'll do the necessary modifications if others think this approach is good.<br><br clear="all"></blockquote>
<div>I also agree that making the methods static would be the better approach. </div><div>Since the class contains a set of utility functions, how about renaming the class to 'Util' on the same time? This will save a bit of line space and help us fix some coding style violations.</div>
<div><br></div></div>-- <br>Thanks and Regards,<div><br></div><div>Madhura Jayaratne<br><div><br></div></div><br>