On Monday, January 31, 2011 10:05:26 AM UTC-5, web2py noob wrote: 
>
> Hi, 
>
> I'm wondering if it's a good practice to use Object Oriented
> Programming in web2py instead of the builting MVC method. OOP is what
> I learned in school but I haven't need it in web2py at this moment and
> i'm very pleased with the MVC paradigm, but want to know if it's
> better start training and developing in OOP with web2py or MVC is just
> a new good and efficient fashion to do almost the same. 
>
> It's worth to say that web2py is my first framework and i'm learning
> python with it. 
>
> kind regards for your answers.
>
 OOP and MVC are not mutually exclusive or different ways of doing the same 
thing. OOP is a programming paradigm (
http://en.wikipedia.org/wiki/Programming_paradigm) and MVC is a software 
architecture pattern (http://en.wikipedia.org/wiki/Model-View-Controller). 
Depending on what you're doing, you may not need to create a lot of your own 
classes in your web2py app, but you should certainly do so where it makes 
sense. Of course, the framework itself uses OOP, and your apps will 
instantiate many web2py classes and call methods on those objects (these are 
all classes: http://web2py.com/book/default/chapter/04#API).
 
If you have any experience working with an ORM (object relational mapper), 
you'll probably notice that working with the web2py DAL (database 
abstraction layer) feels less object oriented. From Wikipedia:
 
"Web2py implements a DAL, not an ORM. An ORM maps database tables into 
classes and records into instances of those classes. The DAL instead maps 
database tables into instances of a class and records into instances of 
another class."
 
So, with an ORM, you are creating your own classes to represent your 
database tables, but in web2py, you use the DAL.define_table method to 
instantiate the web2py Table class. The web2py DAL is object oriented, but 
you're not writing your own classes (for the most part). However, there are 
"virtual fields" (http://web2py.com/book/default/chapter/06#Virtual-Fields), 
which does involve creating classes.
 
Best,
Anthony
 

Reply via email to