Welcome Guest ( Log In | Register )

[ Big| Medium| Small] -

Post new topic Reply to topic  [ 2 posts ] 

Which of the following Javascript patterns do you like?
Wrapped Prototype 0%  0%  [ 0 ]
Composable Revealing Module 0%  0%  [ 0 ]
Parasitic Inheritance 0%  0%  [ 0 ]
Reversed Inheritance Hierarchy 0%  0%  [ 0 ]
Reversed Prototype Chain 0%  0%  [ 0 ]
Total votes : 0
  Sat Feb 11, 2017 1:57 pm

Party Mascot
Disclaimer: This topic's to provide some extra choices for those needing/wanting some protections from being able to access anything from anywhere while still allowing inheritance. As sometimes it completely makes sense for keeping everything public, these choices are entirely optional. Using any of them without any solid reason's just violating KISS for nothing, which should be avoided.

This topic aims to use an easy, simple and small scenario to briefly cover some patterns illustrating Javascript ES5 access modifiers and inheritance.

Bear in mind that those patterns can quickly become antipatterns if they're used without at least thinking twice.
So you're assumed to have at least a basic knowledge on writing Javascript and have written at least several easy, simple and small js files which work without nontrivial bugs.
The focus of this topic corresponds to 'Remembering' in the new version of the Bloom's Taxonomy.

Please note that the following concepts will be used:
1. Final - Functions/variables that can't be redefined after their initial definitions
2. Private - Functions/variables only accessible by the enclosed class/instance/function
3. Protected - Functions/variables only accessible by the enclosed class/instance and their subclasses/instances
4. Public - Functions/variables accessible from anywhere
5. Static - Functions/variables shared by all instances of the same class

On a side note: Strictly speaking, it's nearly impossible to always ensure an object method will always remain private/protected, as advanced programmers can, after thoroughly comprehended the object's API, reconstruct the whole object while preserving its external behaviors, even though its internal states will most likely be lost that way. However, it's such an unreasonably tedious task for nontrivial objects having nontrivial inheritance hierarchies that only truly trivial and/or valuable objects really worth such tremendous efforts. Therefore, let's just regard them as edge cases and move on.

Content Hidden

With all these in mind, let's get started.

Content Hidden

With the context in place, the following patterns can finally come into play. All files implementing all these patterns, as well as their unit tests and integration tests, can be found in my Lockable-Container github.

You're highly encouraged and recommended to read the simplest thing that could possibly work first, which is demonstrated by lockableContainerKiss.js.

Wrapped Prototype
Content Hidden

Composable Revealing Module
Content Hidden

Parasitic Inheritance
Content Hidden

Reversed Inheritance Hierarchy
Content Hidden

Reversed Prototype Chain
Content Hidden

Content Hidden

I'm planning to open another topic to explain how these pattern works in details, which will lead to a solid understanding on using Javascript access modifers and inheritance.
That's all for now. What do you think about these patterns? What do you think about Javascript access modifiers and inheritance in general? Let's drop your 2 cents here :)

My RMVXA/RMMV scripts:

Last edited by DoubleX on Sat Mar 04, 2017 3:19 am, edited 5 times in total.

Top Top

  Wed Feb 15, 2017 3:48 pm

Party Mascot
I've made the following changes:
1. Changed the name of the 2nd pattern from Private Function to Composable Revealing Module.
This change leads to a better indication that the 2nd pattern's a special case of the revealing module pattern.
2. Changed the name of the 3rd pattern from Protected Class to Parasitic Inheritance, which supports multiple inheritance.
I feel very sorry for not realizing that I've just reinvented the wheel.

My RMVXA/RMMV scripts:

Top Top
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

Who is online

Users browsing this forum: No users and 1 guest

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

We are an independent, not-for-profit game making community.
Board Index
About Us
Downloadable Games
Free Browser Games
Games in Development
RPG Maker Support
Game Maker Support
Construct 2 Support
HBGames the eZine
Advanced RPG Maker
Site Announcements
Powered by phpBB © phpBB Group