Jump to content

jawef

Members
  • Posts

    19
  • Joined

  • Last visited

    Never

Everything posted by jawef

  1. I call those utilities classes (see http://en.wikipedia.org/wiki/Utility_class ) and consider them as part of the core of what OOP is but , I agree with some points of the articles that you provided. Most OOP programmers have procedural background and that is not the problem if you work 12 hours a day with a strict OOP language, but with PHP it is a bit different. You must really understand why this class should be a utility class and not an object; otherwise you just curry functional programming in your logic.
  2. You didn’t specify the reason that made you use this approach. Are you “sharing” sessions between 2 (or more) domains? If so there are many ways depending on what you are doing. One of those is making a secure web service, make the application in the domain passing the session id to act as client and request from the provider (the application domain from where the user came) to get the session data.
  3. This is something that has to be done client side, with JavaScript. You could have an array of submit actions, when somebody presses a button if the array is empty submitting through AJAX else pushed in the array. When submitting with AJAX you can define a function to be called on AJAX response (with onreadystatechange). In that function if the array of actions isn’t empty use the first element to generate an AJAX request (and remove it from array) and so on… Of course I didn’t cover even the half of how to do it in real life, but that is just an idea ...
  4. Thank you also DWilliams , I was writing a PHP Websocket tutorial for my colleagues and I just realized from your code that when I decoded from hybi 10 I just ignored close , ping and pong types. When I will finish it I will open new thread since I have many concerns about server performance using Websockets. Again thank you all.
  5. Recently I gave a bad client an ioncube obfuscated code, and the response were a thread for suit or (without saying) a box match … ) so … the main thing is not having bad clients and because you can’t understand them all ... have a nice contract in papers …..
  6. Don’t be harsh to yourself. You said that the first thing you did were to create procedural code, so the key is not making that code OO but Object Oriented thinking from the scratch. This might take some time and some errors but don’t be anxious about it. I have some ideas to your last post. I don’t want to confuse more, so read them just as ideas. You wrote “current season object,” I don’t really understand that. Next, make your objects as close to your data model and verbal avoiding properties that are not serializable like data connection objects or file pointers. The main thing is to watch your data and see the universe that you created. Each entity in this universe has properties and behaviors so it just write down how those entities interact. Hoped I helped a little …
  7. Thank you Spark_BR for your time , I am familiar with the observer pattern, but my framework stands in a lot deferent approach. I am sure though that your example will help others. Maybe what I didn’t made clear is that this method overloading break and flip will happen only to the preset flow functions of the framework (e.g. onPost is used when there is a post , onGet when it is get (or trailing path variables of the controller name in URL), onUse when the controller is used first of all others no matter what and onEntry when it neither post or get (or aren’t onPost / onGet methods respectively in the final Controller) . The first problem that drove me to the pattern I first described, is that there could be some general application actions (like log on for example) that are handled by the abstract application controller from where all the controllers inherit. That means that in order to make it work each controller should has a onPost with parent::onPost() in first line even if that specific controller don’t have any reason to use onPost(). Using the pattern I described if there is post all the onPost methods will invoked from parent to child, and furthermore if the last child – actual Controller don’t have onPost all the onEntry methods will invoked. That pattern helped me a lot in many other design issues. For example if abstract application controller has a onUse that initiate some general public application properties (and the framework don’t automatically find them and set them through visit scope cashing or application scope cashing) than all the final Controllers should have onUse with the first line parent::onUse() . With the pattern I described the framework will invoke before anything else all the onUse methods that exists from parent to child to the current controller.
  8. I must add to my previous answer that regenerating a post to a new Controller is rather a tricky mater. I didn’t found any solution for doing this to what I understand as the proper way (redirecting to new page preserving POST) because sending headers to clients with post doesn’t make sense to it. Of course there are always curl and fsockopen if you want to post and get the contents within the programme but the user want actually redirect. Clarifying that , I ended with my previous approach – holding any post data in season if there is submit through a controller , redirect to the new Controller, use the data of previous Post if there and delete them. That of course exclude posting with redirection to an external page from the application, but for that there is always the option of submitting through curl or fsockopen and get response. Of course that issue arise if you want to submit from inside the application , if you just want give the visitor to submit to other Controller there are numerous ways to do that (Html and Javascript).
  9. Hello, you are talking about something that today I changed to my framework. I used to give the option to kill current Controller and start new one without redirecting, but that damaged the architecture clearness. So today I replaced that option with regenerating a post (changing what need to be changed) to the new Controller. In that way the user sees the URL that that Controller is responsible and it is really more clear to fallow what happens and where. As for search for example or log in there are some common actions that are handled by the Application Abstract Controller from where Controllers Inherits. Of course there are several other approaches … also I would like to read more opinions on that …
  10. It is part of a MVC PHP framework I am about to publish (yes … one more PHP framework). From programming, using that framework, point, there are some preset flow methods that the programmer can use in its controllers [ onUse() onEntry() onPost() onGet() onView() ] . Controllers inherit from framework’s ControllerAbstract but many times it is also good practice to have an application controller abstract class (that all the controllers of the specific application inherit from). Things can be more complex if you have a third level – group of controllers for a specific use (example: admin login Log > AdminControllerAbstract > ApplicationControllerAbstract > ControllerAbstract ( of the framework) ) Flow methods of the controllers are interchangeable and optional (I am keeping this as short as possible … for more just ask). So to get why I am using this pattern here is a real example. Posting is done by actions that may have the controller that refers this action to. But there are some actions that you want for all your controllers (e.g. log in) than you just define them in the onPost() of the ApplicationControllerAbstract, so the framework should invoke first the onPost of the parent and the onPost of the child. One more , the onUse() will be invoked (if exist) before any other flow method ( regardless if it is onPost() onEntry() or onGet() ) and has meaning of initialization any property that is needed if it is not initialized , so the framework should first invoke the parent’s onUse() and then the child’s. I have tried to explain why I am using this pattern, as for the framework of course this is just a glimpse since it is not the topic. requinix I am not breaking the concept of inheritance. There is a reason why you can do such a thing. Instance of (b) is also an (a) and a (proA) and a (root) invoking a method of parent class in its context don’t brakes the concept of inheritance (maybe bends it…hehe) because after that b still is as were for any other calls. Thank you for your responses, any more opinions are more than welcomed…
  11. Sometimes I thing that I have created a design pattern but that in reality already exists, and has, moreover, a name. Please share with me if you know that pattern that I am going to describe , and if not your opinion about what name should have. When you have a child class with the same method name as the parent then it overloads it and only the child’s method occur. Of course in first line of that child’s method you can call the parent’s method (e.g. parent::methodName(); ) and than the parent method will happen. I am talking about a pattern that will do that using reflection. Also use any private properties to their class contexts Example: <?php header('Content-Type: text/html; charset=utf-8'); // Classes that will be used to the example class root { } class proA extends root { public $txt = ""; private $pr = " (and something private from proA) "; public function onEntry() { $this->txt .= "proA:onEntry()".$this->pr." ---> "; } } class a extends proA { private $pr = " (and something private from a) "; public function onEntry() { $this->txt .= "a:onEntry()".$this->pr." ---> "; } } class b extends a { public function onEntry() { $this->txt .= "b:onEntry()"; } public function getTxt() { return $this->txt; } } // Starting reflection to class b and create an instance $reflectionClass = new ReflectionClass("b"); $instance = $reflectionClass->newInstance(); // Creating an array with reflection classes of all line classes // (except the root class) reverse it in order to go from parent // to child and than push to that the original reflection class. $reflectionClasses = array(); $parent = $reflectionClass->getParentClass(); while($parent && $parent->getName() != "root") { $reflectionClasses[] = $parent; $parent = $parent->getParentClass(); } $reflectionClasses = array_reverse($reflectionClasses); $reflectionClasses[] = $reflectionClass; // Invoking the onEntry() method using the original instance // an all the reflection classes ordered from parent to child for($i=0; $i<count($reflectionClasses); $i++) { if( $reflectionClasses[$i]->hasMethod("onEntry") ) { $reflectionClasses[$i]->getMethod("onEntry")->invoke($instance,""); } } // And finally invoke the getTxt() method of b class instance echo $reflectionClass->getMethod("getTxt")->invoke($instance,""); // The result is // proA:onEntry() (and something private from proA) ---> a:onEntry() (and something private from a) ---> b:onEntry() ?>
  12. Don’t stick to PHP , OOP is a way of thinking , if you master it you can write this way even in languages that aren’t object oriented. Find books about OO architecture and mess your mind about how you would implement those in PHP.
  13. $sql = new SQL $sql->select('news, date')->from('news')->execute(); Is a really but practice of OOP. If a framework has this way of doing thinks then move on. OOP should produce simple code and understandable in 10 – 15 lines of code block. If you done it the right way (with instances) one line of that is 5 … that is not good practice.
  14. You could go this way you mentioned. If the admin is you there is no need to use either WYSIWYG or DB , you could create a form in a file (with some admin privileges) and enter there your content in HTML, then PHP will save it in a file (could be .html) and use it as include. But … this is the easy , risk full and dirty way to go, actually it is “what CMS is” just to understand the concept. If you will use it often or in more ways, than you are describing, it is cheaper in recourses to think about programming and data bases.
  15. I strongly believe that scaling is something that written theory (even in internet) is far behind real word examples. I am not referring to technical scaling (since I have little to do with these) like servers, that I believe is the easy part if you have the money, but in the programming – analysis’s aspect. Let me remind that few years ago “cashing” was something wrong in languages like PHP and this point of view was the dominant. First of all you should use a good testing framework and do a lot of tests in your own. There are few basics (that not everyone agrees) but to find your way you should make your own tests. And let me point one other aspect that is rarely mentioned, a good scaling technique in one application – site might not work as well in another.
  16. Most times using a database is easier for me and more efficient but there few exceptions. Properties files (either application properties or languages application messages) and application scope cashing. In latter case I use flat files where objects have already been serialized. Of course in both cases those files shouldn’t be in public_html but in a protected directory above (in a sub directory of src for example).
  17. jawef

    Hello all

    Hello all, Programming was something that came natural in my life when I was ten and my father came to home an Amstrad 6128 (it had a great yellow book with it … introducing GW BASIC) next step was C (I never mastered C) and new computers new languages and eventually internet. Although I am programming through 10 (my first program was a game but the next one was an application for a factory) to be programmer wasn’t in my days the ideal thing to be. So I got my first degree in economics (business administration)… but … I have never stopped programming and producing code , and in one job that I where, (as minor administrative executor) a big (maybe the biggest around) IT company noticed all the programs that I made for making our life better , and offered me a job. That was my next start as programmer, with a lot of work, and my master degree in computer science. Programming maybe is the easy choice for me (as a person) but I could be a bad one, if I didn’t worked (a lot ... and in the beginning for less money then my previous job). Finally I am not sure that we are good in things that we like or we like things that we are good at… (also I am not native English speaker … but you should have noticed that as far)
  18. Of course there is no need to use OOP. Of course carrying reusable classes (or even a framework) might have a cost. But if you stay in OOP best practices will make your code “clean gold” that you will enjoy change it or use it in other projects. OOP is not a one way road but it is the cleanest one we have so far.
  19. If your content is static and it is produced with some PHP program then you definitely should do what you mentioned (produce it once as html and use it this way). If the content is rather static (meaning that it is changed rarely) then, it also has point to store it and use it as html (all time losses will charge the administrator of the site … but this is something that he should be ready to deal). In my point of view there are two separate different scopes of cashing. Application scope and thread (user) scope, this has to do with objects and how your application – site works. If you don’t need a programming language like PHP and you are fine with HTML produced by PHP there is nothing wrong to that. This is just my opinions (and not “the truth”) and I hoped that I contribute sharing with you. (We all are ignorance in one field or other, starting from that is a very good sign for your feature)
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.