I do apologize for the amount of posts I made today, but then again I
have a lot of questions.
I'm trying to create a web application using Joose as my programming
structure (OOP).
Now, my app has quite a lot of logic that are related to visuals. I
wonder how I should handle this. Most people use a MVC pattern in
platforms like flash, is this suitable for Joose?
Anyway, at the moment I have the following:
- Main.js
- Interface/MainHandler.js
- Interface/MainPageStructureRole.js
- Interface/Buttons/NewSource.js
This is what it looks like:
//Main: handles main application logic, acts as an entry point
Class("Main", {
use : "Interface.MainHandler",
//static
my : {
methods : {
//called before DOM is ready
initBeforeDOMReady : function() {},
//called after DOM is ready
initAfterDOMReady : function() {
console.log("Init after dom ready.");
//load main interface
Interface.MainHandler.load();
}
}
}
});
Class("Interface.MainHandler", {
use : "Interface.Buttons.NewSource",
does : ["Interface.MainPageStructureRole",
"Interface.MainPageCSSRole"],
my : {
has : {
isLoaded : {is : "rw", init : false},
newSourceButton : {is : "rw", init : null}
},
methods : {
load : function() {
console.log("Interface.MainHandler load.");
if (this.getIsLoaded()) throw "Interface.MainHandler has already
loaded.";
//set main page structure
this.resetMainPageStructure();
//set main page css
this.resetMainPageCSS();
//load element: Buttons.NewSource
this.newSourceButton = new Interface.Buttons.NewSource();
this.newSourceButton.load(this.mid1Element,
this.onSourceButtonClick);
//loaded
this.setIsLoaded(true);
},
onSourceButtonClick : function() {
console.log(this);
}
}
}
});
Role("Interface.MainPageStructureRole", {
my : {
has : {
bodyElement : {is : "rw", init : null},
top1Element : {is : "rw", init : null},
mid1Element : {is : "rw", init : null},
mid2Element : {is : "rw", init : null},
mid3Element : {is : "rw", init : null},
bot1Element : {is : "rw", init : null}
},
methods : {
resetMainPageStructure : function() {
//set body
this.bodyElement = $("body")[0];
jQuery(this.bodyElement).html("");
//remove existing elements
this.top1Element = null;
this.mid1Element = null;
this.mid2Element = null;
this.mid3Element = null;
this.bot1Element = null;
//create new elements
this.top1Element = $("<div/>")[0];
this.mid1Element = $("<div/>")[0];
this.mid2Element = $("<div/>")[0];
this.mid3Element = $("<div/>")[0];
this.bot1Element = $("<div/>")[0];
//add to body in order
$(this.bodyElement).append(this.top1Element);
$(this.bodyElement).append(this.mid1Element);
$(this.bodyElement).append(this.mid2Element);
$(this.bodyElement).append(this.mid3Element);
$(this.bodyElement).append(this.bot1Element);
}
}
}
});
Class("Interface.Buttons.NewSource", {
after : {
initialize : function(params) {
console.log("Interface.Buttons.NewSource initialize.");
}
},
has : {
isLoaded : {is : "rw", init : false},
domElement : {is : "rw", init : null}
},
methods : {
load : function(parentElement, clickCallback) {
if (!parentElement) throw "Load requires parentElement.";
if (this.getIsLoaded()) throw "Button has already loaded.";
//set dom element
this.setDomElement(jQuery('<input type="button" value="New
Source"/>')[0]);
//add to parent
jQuery(parentElement).append(this.getDomElement());
//set event listener
thisButton = this;
jQuery(this.getDomElement).click(function() {
clickCallback();
});
//loaded
this.setIsLoaded(true);
},
unload : function() {
if (!this.getIsLoaded()) throw "Button has not loaded yet.";
if (!this.getDomElement()) throw "No DomElement was set.";
//remove dom element
jQuery(this.getDomElement()).remove();
this.setDomElement(null);
//unloaded
this.setIsLoaded(false);
}
}
});
-- That was a lot of code. Sorry. --
Anyway, as you can see I am doing some things that I probably shouldn't
do. For example, look at the MainPageStuctureRole.js file. This probably
isn't what roles are supposed to do right?
Basically, I'm looking for a way to create webapps where visuals and
logic are separated in an easily maintainable OOP way.
If anyone has any suggestions/comments that'd be appreciated.
- Tom
Now, my app has quite a lot of logic that are related to visuals. I
wonder how I should handle this. Most people use a MVC pattern in
platforms like flash, is this suitable for Joose?
--
You received this message because you are subscribed to the Google Groups "Joose" group.
To post to this group, send email to joos...@googlegroups.com.
To unsubscribe from this group, send email to joose-js+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/joose-js?hl=en.
Thanks for your help. I realize that what I have at this moment makes no
sense at all, which is why I posted.
Anyway, your feedback really helps. However, while I do understand the
purpose of a role in your specific twitter example, I cannot see how
this can be used in many cases. Why would this replace multi
inheritance?
For example, I have a general UIHandler class. This handles the main
interface. It'd have to do a lot of things, which would create huge
functions. This is why I put the PageStructure etc. in a Role. This is
not the purpose of a Role though. So, how should I do these kind of
things? How would you organize such UIHandler?
Thanks again.
- Tom
On Thu, 2010-11-11 at 11:39 -0500, Sir Robert Burbridge wrote:
> scribes wha
Hi Robert,
Thanks for your help. I realize that what I have at this moment makes no
sense at all, which is why I posted.
Anyway, your feedback really helps. However, while I do understand the
purpose of a role in your specific twitter example, I cannot see how
this can be used in many cases. Why would this replace multi
inheritance?
For example, I have a general UIHandler class. This handles the main
interface. It'd have to do a lot of things, which would create huge
functions. This is why I put the PageStructure etc. in a Role. This is
not the purpose of a Role though. So, how should I do these kind of
things? How would you organize such UIHandler?
Thanks again.
- Tom
On Thu, 2010-11-11 at 11:39 -0500, Sir Robert Burbridge wrote:
> scribes wha
--
That's great feedback once again. Thanks.
Only comment I have regarding the UI class you created, it does have the
named properties, however there has to be a place where you initiate the
creation of pages and handle the interface logic. For example, you have
to set what page loads first, and you have to make something happen when
a button is clicked.
Especially the "setting what page loads first" seems like a job for the
UIHandler, right?
- Tom
On Mon, 2010-11-15 at 10:45 -0500, Sir Robert Burbridge wrote:
> On Thu, Nov 11, 2010 at 11:59 AM, Tom <tomm...@gmail.com> wrote:
> Hi Robert,
>
> Thanks for your help. I realize that what I have at this
> moment makes no
> sense at all, which is why I posted.
>
> Anyway, your feedback really helps. However, while I do
> understand the
> purpose of a role in your specific twitter example, I cannot
> see how
> this can be used in many cases. Why would this replace multi
> inheritance?
>
> Let's say you have a page with several different UI elements you want
> users to be able to tweet about:
> * A side-bar panel that displays rss info
> * A notification system that pops up messages
> * Normal page images
> * Article comments (from users)
> And several elements you don't want users to be able to tweet about:
> * Menu items
> * A side-bar panel that displays a tag cloud
> * Normal page audio (streamed mp3 or something)
> * Article comments from the site admin (such as "article
> 1. A function maps input to output (with input X, I always get
> result Y).
> 2. Every function should do only one thing. (i.e. Atomicity of
> code)
> 3. Two functions should never do the same thing (i.e. DRY: DON'T
> REPEAT YOURSELF!)
> And here is the corresponding orthopraxy:
> 1. Start writing your code procedurally
> 2. When you find you are repeatedly creating the same procedures,
> move the repeated code into a function.
> 3. When you find you are repeatedly creating the same functions,
> For more options, visit this group at
> http://groups.google.com/group/joose-js?hl=en.
>
>
>
> --
> You received this message because you are subscribed to the Google
> Groups "Joose" group.
> To post to this group, send email to joos...@googlegroups.com.
> To unsubscribe from this group, send email to joose-js
Sir,
I just wanted to say that this message is one of the most eloquent and
illuminating texts on inheritance, roles, composition, and design in
general that I have ever read.
Have you written any books? Do you have a blog? Twitter?
Thank you,
--
Daniel Brockman, partner & developer
Go Interactive <http://gointeractive.se>
Twitter: http://twitter.com/dbrock
Telephone: +46706880739
To unsubscribe from this group, send email to joose-js+u...@googlegroups.com.
That's great feedback again. Thanks.
I do understand your point that everything should be considered a
library. I had followed this philosophy for the individual elements, the
UIHandler for me was more like a handler that'd put all these individual
elements together (I only have 1 page).
I can see why this would be inappropriate. You initiate your interface
in init.js. I have to say though that your example seems to be quite a
basic situation. For example, if I want to create specific pages that
have different actions when certain events happen, I would have to
create a handler for this, right? This is what I originally meant to do
in UIHandler.
Thanks again.
- Tom
On Wed, 2010-11-17 at 15:16 -0500, Sir Robert Burbridge wrote:
> Sorry, Tom; I missed your question when I read the e-mail before.
>
> Let's look at the specific points you asked about in the context of
> the UI class I wrote up before:
> * Initiate page creation
> * Determine which page loads first
> * Make something happens when a button is clicked
To unsubscribe from this group, send email to joose-js+u...@googlegroups.com.
If you really enjoy writing, I can recommend you the following topics:
- How to convince investors of an idea without giving your idea away
- How to get in contact with investors for a project
- How to deal with international contracts and law when selling projects
- When one should decide to create a company rather than work as an
individual
- The pros/cons of working as an individual
- How to take culture differences of international target markets into
account
- How to create international business or product names appealing to
international targets
- How to create a working user-driven system where input is made by a
part of the people interested in the output
- How to market a project with low liquidity available
- How to market a project with average liquidity available
- comparison of IDEs for linux for client and server sided Javascript
- proper understanding of OOP concepts
- need for multi inheritance or role alternatives
- How to separate visuals from app logic
- How to setup a high availability cloud based infrastructure where load
is balanced, and if balanced visitors are appointed to the nearest
servers available (GeoDNS or other alternatives, some will not be
possible with a cloud service - why?)
These are in no order. Obviously one cannot be an expert in all these
fields, but they are what interests me -- so you might get some
inspiration.
Good luck.
Regards,
Tom
> For more options, visit this group at
> http://groups.google.com/group/joose-js?hl=en.
>
>
>
>
>
> --
> You received this message because you are subscribed to the Google
> Groups "Joose" group.
> To post to this group, send email to joos...@googlegroups.com.
> To unsubscribe from this group, send email to joose-js
Sorry for the late reply. I will try to create a good example as soon as
I can, but this might take a while.
Thanks.
- Tom
> To unsubscribe from this group, send email to joose-js
To unsubscribe from this group, send email to joose-js+u...@googlegroups.com.