Model-View-Controller Observer Observable — A[n] Incoherence Rambling

By Xah Lee. Date: . Last updated: .

Wikipedia Model–view–controller (aka MVC)

by the way, if you don't know what MVC is, you can think of it as:

here's a tutorial from Apple:

The Model-View-Controller (MVC) design pattern assigns objects in an application one of three roles: model, view, or controller. The pattern defines not only the roles objects play in the application, it defines the way objects communicate with each other.

from https://developer.apple.com/library/ios/documentation/General/Conceptual/DevPedia-CocoaCore/MVC.html

the Apple's tutorial is quite short and to the point. read it.

basically, the code in your app belongs to one of the 3 categories: model, view, controller.

though, the MVC seems to be have quite a lot variations and the original mvc from SmallTalk is a completely rather different thing.

Some MVC has View talking to Model.

here's others:

The MVC is actually complicated. It began life in SmallTalk language. But its idea of MVC is hardly what we think of MVC. But, y'know? when you talk abstractly about software engineering, too often, you don't know what u talking about, and people will nod heads. (this is opposed to math or formalism, where, like computer programs, you couldn't possibly go wrong and not know it.)

when reading about MVC, alone with it is Observer Pattern. The patterns shit is truly garbage. [see Why Software Suck]

i started to read about Observer Pattern, like other pattern stuff, it's typically incomprehensible.

But here's the best, simple, concrete explanation:

from http://c2.com/cgi/wiki?ObserverPattern

and we have Wikipedia

The observer pattern is a software design pattern in which an object, called the subject, maintains a list of its dependents, called observers, and notifies them automatically of any state changes, usually by calling one of their methods. It is mainly used to implement distributed event handling systems. The Observer pattern is also a key part in the familiar model–view–controller (MVC) architectural pattern.[1] The observer pattern is implemented in numerous programming libraries and systems, including almost all GUI toolkits.

Observer pattern

[Observer (Java Platform SE 8 )]

// the idiocy of the OOP and idiocy of observer pattern
// EXPLAINED!

// this is a var
var x = 1;

// when x is change, all the following needs to change too
var a = x+1;
var b = x+2;
var c = x+3;
var d = x+4;

// solution. We define a update function uu
function uu (n) {
    a = n+1;
    b = n+2;
    c = n+3;
    d = n+4;
}

console.log( a ); // 2

x = 3;
uu(x);

console.log( a ); // 4

the motherf Observer and Observable my ASS. These OOP scumbags and voodoos.

In other words, the observers are subscribers, and the observable is the publisher.


but this essay talks about something else.

i never worked or had experience or understand Model/View/Controller.

so, talking to myself for an hour, thinking about it…

(these days, i dunno if because i'm getting old and learning new things isn't as easy as younger, or, i've become stubborn and peculiar in my ways that things other coders don't have to think much about but i need to make a fuzz thinking. Probably some of both.)

first, we want to explore in the direction of software, its essential components, core, or structure. Something like that. (we are doing, thinking from scratch. That is, we try to just think and find the logical foundation or direction that may lead us to something we wish to understand. (typically, when this succeeds, we understand much deeper, because, essentially we invented it ourselfs!))

the software we are thinking are web based, with potentially massive number of users. For example, twitter, facebook, blogger, amazon, ebay, estore, disqus, all count. (not necessarily those massive scale) (is there a name for this type of software? Web site isn't because personal home page is also a web site. Web app isn't it because that's more like a personal software for the phone. In gaming, they have similar called Massively Multiplayer Online Game.)

first idea come to me is, we need data. Data of customer, and anything else. For example, let's say estore platform (such as amazon). We have data of customer, passwords, shopping cart, inventory, mechants, merchant store url, many many states, sessions, buyer credits, merchant credits, merchant/buyer account info, etc. All are data. Data, is perhaps the most essential, the most core. If it's info we need, it's data.

then, am thinking of the “view”, that is, the interface to users, the website. This aspect, is also essential. Users of our site need to view the site, see things, login, click, etc. Not via telepathy.

lastly, when user does something, the data changes. Not just arbitrarily, but by certain logic or control. For example, when user xyz logs in, xyz's login status changed, not somebody else. Thus, this is, perhaps, the “controller” part of the “Model View Controller”.

though, i felt strange, that somehow my toughts just fall into the MVC as is, even though, of course, i began as a way to think what MVC is.

now, the above is some logical thinking, to myself. The actual MVC of the web, exactly what code is what, their meaning to MVC, might be another story. Also, i note, there's variations to MVC.

by the way, i've tried to learn MVC before. Once spent perhaps a week on backbone.js. I can't say i understood anything or went anywhere. I still have my start of a tutorial: Backbone Tutorial. (by the way, their website now seems improved. Before, it's really terse barebones. Now, it seems to have some explanation about MVC. http://backbonejs.org/ )

the other time i tried to learn MVC is reading the book 〈JavaScript Web Applications〉. I didn't come away learning much at all. (by the way, it's not a good book. (Try my book JavaScript in Depth) )

If you have a question, put $5 at patreon and message me.