views:

76

answers:

2

I have a problem about structures of the complex applications .Because my knowledge background does not come from education , i have had always problem about application's layers , design patterns and programing structures.First of all , I can do whatever I want with php , because I know common functions and I have experience with php. But I want to create bigger and more complicated applications than i did before ,so I always ask questions myself while I am writing code . Is this best place to do this? , is this the best way to do this? , do people use this way to do the same thing?. To answer these questions correctly, I created my own small mvc php framework which really looks like Zend Framework. I did this because I want to clarify all parts of the application . I know that there are lots of design crimes in my framework and all my applications . And I think that the main problem is the border between Controller and Model . I asked lots of questions about this in SO ,but still it is not clear for me . Therefore , I will explain what I know and what I do , and please show my mistakes ,and correct them , or just explain some information about design patterns ,or just show my problem so I can make research about it , because I do not even know my problem , but I know that what I do is not the best way , so I can improve myself .

What i know

  1. I know active record pattern . For example , we have user class , we use same class to save data to database , and we use same class as a object . So object is active we can create one then if we change it we can save it with same class ( $user = new user('Oguz'); $user->save();)
  2. I know factory pattern . We have to classes for one object (User_Factory and User). We use user_factory class to acces database for example get user or delete user . And user class is the object it self.

Ok my problem starts when there is a connection between objects (not like manytomany or belonsto ).For example , we have a video website which has a favorite system . The process of adding favorite consists of these steps (1-check the video with this id, check the user with this id . validating steps). While we are just adding or updating just one object we user other objects too (User factory and video factory). Generally i can do all this things in controller . But i fell that this is not the best place to do this . Because i call these steps as a process (adding favorite process ).So this process should not go in controller because we may want to use same process as an api in another controller-action . So i feel like there should be another place which includes this processes for example process library. I do not even know which programing problem i am talking about.

The connection between object does not just exist in validation step.For example think about search process. when user search a string first we have to create new search row (for lastest searches stuff) , then we have to search youtube , if we can not find we have to search other video sites etcetera .So this action is a process search process , i think putting the all logic in controller is a correct way to to this . we use lots of classes and objects so i can not put this process in search objects class .

Thank you for everyone , Sorry for my english . i am very eager to learn more , i have been using php since i am 11 (I am 19 now) . i will be a college student next year (i hope) . i hope this will be a great place to learn more ask more and do more . I ask it now because i can not ignore these questions and wait until becoming college student. Even if you do not answer or you can not understand my question thank you for your reading. Please feel free to edit and improve my question .

I really like coding complex applications (may be not complex for lots of you) . I think that solving problems is very enjoyable.Therefore I am dying to learn what is the standarts of enterprise level coding .Maybe it is not necessary for my case . but i want to create my applications with the best programing approaches.

+2  A: 

I think one of the best things you can do is dig in and understand, really understand how things work. In the arena of web development, we are typically isolated from the details of TCP, packets, transports, protocols, etc... But sometimes, it is so isolated, that we forget to learn how it works, and as a result, stick ourselves in a little box.

I've been programming PHP professionally for nearly 10 years. I've never used an MVC framework. I've always separated user interface from application logic from database access.

We don't need a bunch of "patterns". We need true understanding of the problem, and the vision to create an elegant solution, re-using other work as much as possible.

So I guess I am suggesting that you switch your focus from trying to make your application fit into a pattern, and re-consider the logic needed to successfully complete your application. Many times, it is very simple, but we tend to over-complicate it.

Throw off the handcuffs of MVC and patterns... (and then watch me get downvoted for ranting against the status quo).

Good luck with everything. And by the way, you will learn far more about programming in 4 years of doing it, than 4 years of college. Not to say you should or should not go to college, but just be aware that in many cases, you already know more than your professors will about real-world programming.

gahooa
@gahooa: High five! ;)
just somebody
+2  A: 

MVC is a fashion blooming 20 years late. If you feel it pushes you into "wrong" code, it's because that's just what it does. Do things from the first principles. And... The community is not a shrine of divine wisdom. We're just a bunch of loud code monkeys. Use your own brain. And... MVC is a fashion blooming 20 years late. If you feel it pushes you into "wrong" code, it's because that's just what it does. Do things from the first principles. And...

Good luck, and enjoy your endeavors!

just somebody
Laughing out loud... "And... The community is not a shrine of divine wisdom. We're just a bunch of loud code monkeys."
gahooa