<pedrocorreia.net ⁄>
 

<JavaScript for C# programmers: object inheritance ⁄ >




clicks: 317 317 2009-03-05 2009-03-05 goto programacao myNews programacao  Bookmark This Bookmark This


I know, it's taken you years to understand class inheritance until you could do it in your sleep. It took me years as well. We've had it engrained in us for a while: design a class to model some object in our problem space, worry about encapsulation and behavior, think about creating descendants that increase the specificity of our first more-general class, and perhaps keep on going to produce higher, more-specific classes. We exult in those class models and in the type-safety they give us.

Some of us, as we learn more, start to find that the implementation inheritance model gets to be too restrictive and too wordy. We start experimenting with the interface inheritance model where, essentially, we think about inheritance of behavior rather than of behavior plus data. Our class models become shallower and not filled with classes than descend from classes which descend from others and so on all the way down. We use delegation of the interface as a coding model.

But JavaScript doesn't do all that. It has objects inheriting from objects. Period. Furthermore those objects are dynamic in nature: we can add new members or remove them at a moment's notice. No, this is not the description of anarchy, but a realization that perhaps classes are just too restrictive. Certainly, you can use libraries like Prototype that try to provide you with a class model type structure to your applications, but it is far better to just embrace the way that JavaScript works.

The problem is that JavaScript is conflicted in what you do for inheritance. Despite the speech from the high ground just then that JavaScript objects inherit from other JavaScript objects, there's so simple support for it in the language. Instead we have this unholy trinity of constructors, prototypes and the new keyword that hide object inheritance in order to smooth the way for us developers coming from a classical object-oriented language.



este é só um excerto do artigo, para aceder ao artigo completo, clique no link em baixo:
this is just a small excerpt from the article, to access the full article please click in the link below:

http://blog.boyet.com/blog/javascriptlessons/javascript-for-c-programm...




Subscribe News RSS  Subscribe News Updates by E-mail





myNews <myNews show="rand" cat="programacao" ⁄>

Android Intents - Tutorial

Intents allow the application to request and / or provide services . For example (...)

clicks: 42 42 2010-07-30 2010-07-30 goto url (new window) vogella.de/arti... goto myNews programacao


Memoizing higher-order functions

Memoization incrementally converts functions into data structures. It pays off w (...)

clicks: 36 36 2010-07-29 2010-07-29 goto url (new window) conal.net/blog/... goto myNews programacao


JavaScriptSerializer - Dictionary to JSON Serialization and Deserialization

Few weeks ago I was working with the JavaScriptSerializer for serializing objec (...)

clicks: 43 43 2010-07-29 2010-07-29 goto url (new window) weblogs.asp.net... goto myNews programacao


Android Development - Hierarchy Viewer

The Android SDK comes with a wide variety of tool that are intended to help deve (...)

clicks: 43 43 2010-07-29 2010-07-29 goto url (new window) barebonescoder.... goto myNews programacao


Introducing ASP.NET MVC 3 (Preview 1)

This morning we posted the "Preview 1" release of ASP.NET MVC 3. You can downlo (...)

clicks: 80 80 2010-07-28 2010-07-28 goto url (new window) weblogs.asp.net... goto myNews programacao


20+ Required Windows Apps: Web Designer's Choice

In April, Jeffrey Way gave us a list of the "20 Mac Apps You'll Use Every Day." (...)

clicks: 56 56 2010-07-28 2010-07-28 goto url (new window) net.tutsplus.co... goto myNews programacao


Android - Multithreading For Performance

A good practice in creating responsive applications is to make sure your main UI (...)

clicks: 45 45 2010-07-27 2010-07-27 goto url (new window) android-develop... goto myNews programacao


Uploading a File (Or Files) With ASP.NET MVC

I wanted to confirm something about how to upload a file or set of files with AS (...)

clicks: 76 76 2010-07-27 2010-07-27 goto url (new window) haacked.com/arc... goto myNews programacao