OOP versus MVC in web2py question

253 views
Skip to first unread message

w2padawan

unread,
Jan 31, 2011, 10:05:26 AM1/31/11
to web...@googlegroups.com
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.

Bruno Rocha

unread,
Jan 31, 2011, 10:46:09 AM1/31/11
to web...@googlegroups.com
You can mix OOP with MVC.

You can create your own modules, plugins, validators and widgets using Full OOP, then when creating your MVC application you will consume your OOP.

Bruno Rocha
http://about.me/rochacbruno/bio


2011/1/31 w2padawan <web2p...@gmail.com>

Michele Comitini

unread,
Jan 31, 2011, 11:23:59 AM1/31/11
to web...@googlegroups.com
There is no OOP vs MVC the two are orthogonal.  You can implement MVC using OOP or not.
making things (too) simple:
 - python -> OOP
 - web2py -> MVC

mic

2011/1/31 Bruno Rocha <rocha...@gmail.com>

w2padawan

unread,
Jan 31, 2011, 11:30:34 AM1/31/11
to web...@googlegroups.com
Thanks for your answer. I appreciate your time :)

I know that OOP and MVC are not exclusive (like programming paradigm
!= design pattern), my doubt is about if I really need to use OOP if
I'm not developing any widget or plugin, but using the tools that
web2py already have to build an application.

2011/1/31 Michele Comitini <michele....@gmail.com>:

Anthony

unread,
Jan 31, 2011, 11:35:35 AM1/31/11
to web...@googlegroups.com
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
 

Anthony

unread,
Jan 31, 2011, 11:45:39 AM1/31/11
to web...@googlegroups.com
On Monday, January 31, 2011 11:30:34 AM UTC-5, web2py noob wrote:
Thanks for your answer. I appreciate your time :)

I know that OOP and MVC are not exclusive (like programming paradigm
!= design pattern), my doubt is about if I really need to use OOP if
I'm not developing any widget or plugin, but using the tools that
web2py already have to build an application.

Right, you probably don't need a lot of your own classes if you're just using the existing web2py tools, though at times it may be helpful to extend existing web2py classes to alter the behavior or add functionality.
 
Anthony

w2padawan

unread,
Jan 31, 2011, 11:49:53 AM1/31/11
to web...@googlegroups.com
Thank you Anthony for such a good answer. You have been very much help
for me. I was confusing with so little until now.
Best regards and may the force be with you :)

2011/1/31 Anthony <abas...@gmail.com>:

Anthony

unread,
Jan 31, 2011, 11:57:06 AM1/31/11
to web...@googlegroups.com
You are welcome.
 
Anthony
Reply all
Reply to author
Forward
0 new messages