Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django-like Framework Pattern

I have been using Django for many years (since Django 1.2). and in the past, I used different type of web frameworks (such as CakePHP, Rails, ASP.NET MVC, and some other full-stack framework). Django wasn't my first framework.

Different frameworks have differences in their approaches and benefits. There are certain part of those framework I like and I don't. In this context, I'd like to look at the design of Django Framework in more specific.

After transition to Django, I like how it design its framework. When learning a new language (such as Go, Scala, Ruby, Haskell), I try to looks for a framework that has some similarity in its design especially those I mentioned later.

The following are the 2 Django framework design decision that is very different:

  • it encourage pluggable apps or apps reusability. Hence:
    • moving away from monolithic design by Jacob Kaplan-Moss
    • using multiple apps to create a full feature site, without any model or logic
    • writing a Project-less Django mentioned in Practical Django Projects by James Bennett
  • it uses Model View Template instead of classical MVC:
    • mentioned in FAQ.
    • view describes which data is presented
    • template describes how the data is presented
    • a view normally delegates to a template
    • controller is probably the framework itself: the machinery that sends a request to the appropriate view, according to the Django URL configuration.

I would not believe that Django pioneer such features. I believed this pattern is very common in Framework Design. Just that I have no idea, what is this (design) pattern called? This concept is very useful to be applied in other framework. I believed knowing the name of the pattern could help me understand or even build a new framework on different language with the same concept.

Currently there are tons of web framework, most of them are following the classic MVC pattern. Some use the concept of plugin to add certain capability. Plugin however solve the reusability in different approach depending on the context.

So I did tried to learn as many framework I could in order to find an alternative framework in different languages. Hoping that I could find out the pattern that Django use. However, it is very difficult for me to learn all of them. In fact, I haven't found one so far.

I have been searching for:

  • Django like framework in 'ruby'
  • Django like framework in 'Java'
  • Django like framework in 'Haskell'
  • Django like framework in 'Go-Lang'
  • Django like framework in 'Scala'

Unfortunately, none of them really, highlight the concept that I'm interested in.

In this Q&A, I would like to know what do people call such framework? (Or What pattern is Django use?) Would be good if you could give a references in this design which other framework might have been using it too?

like image 304
Yeo Avatar asked May 09 '15 23:05

Yeo


2 Answers

Looking at Django design philosophies

I think they use/combine a lot of different design patterns trying to fulfill the philosophies. It's difficult to map to a single concept.

Tip is to look at Software Design Pattern and it should be possible to identify many patterns are used in django. Many patterns are of course common in other frameworks as well.

For example (patterns more or less used):

  • modelform_factory maps to "Builder"
  • QuerySet can be mapped to "Lazy initialization"
  • The ORM/database mapped to "Adapter"
like image 184
Daniel Backman Avatar answered Sep 22 '22 18:09

Daniel Backman


What is it about django that you cannot do in other languages?

  • is it the access to the database, or the models? - no, python also has SQLAlchemy; ruby has Active Record...
  • is it the views, or web framework? - no, you can provide views with Flask, Pyramid, rails, php ...
  • it is the templating system? - no, you also have Jinja; mustache, Liquid...
  • is it the admin contrib packages? - no, you have phpmyadmin, workbench ...
  • is it a set of libraries to make your development easy? a toolkit?

django has great tooling, many packages you can use; it is a platform, meaning it has enough of a core to be the starting point of many projects, and enough community behind it to have many packages to make integration into a turn-key solution a breeze.

django uses the DRY (Don't Repeat Yourself) principle as a design philosophy. From the point of reusability, keeping clear responsibilities for each piece / app makes it easy to reuse components. But that doesn't take a well-designed platform; the emphasis should be on the components that are written in a way to be reused. E.g. generic tagging, configuration / data-driven components...

like image 39
dnozay Avatar answered Sep 21 '22 18:09

dnozay