corsasport.co.uk
 

Corsa Sport » Message Board » Off Day » Geek Day » Real world examples of classes in OOP » Post Reply

Post Reply
Who Can Post? All users can post new topics and all users can reply.
Icon:
Formatting Mode:
Normal
Advanced
Help

Insert Bold text Insert Italicized text Insert Underlined text Insert Centered text Insert a Hyperlink Insert Email Hyperlink Insert an Image Insert Code Formatted text Insert Quoted text
Message:
HTML is Off
Smilies are On
BB Code is On
[img] Code is On
Post Options: Disable smileys?
Turn BBCode off?
Receive email notification of new replies?

DaveyLC

posted on 14th Aug 14 at 11:56

quote:
Originally posted by A2H GO
quote:
Originally posted by gooner_47
Why does it suck?


It sucks because I like Objective-C so much. :lol:


Odd-bod :D


A2H GO

posted on 14th Aug 14 at 11:13

quote:
Originally posted by gooner_47
Why does it suck?


It sucks because I like Objective-C so much. :lol:


DaveyLC

posted on 14th Aug 14 at 09:43

Other than having the same syntax?


Rob_Quads

posted on 14th Aug 14 at 09:38

Javascript bugs me because it doesn't have anything to do with Java lol


DaveyLC

posted on 14th Aug 14 at 07:30

JavaScript sucks because its not really object or pointer based.. For example when using an 'event' function it literally passes the code of the function so everything else is out of scope.

BUT for what it does its brilliant, what else is so cross-platform?

[Edited on 14-08-2014 by DaveyLC]


gooner_47

posted on 13th Aug 14 at 23:30

Why does it suck?


A2H GO

posted on 13th Aug 14 at 19:20

I'm building a web app for the company I work for using Ionic and AngularJS at the moment. Never written Javascript before or used this platform but pretty straightforward tbf (ps. Javascript sucks :lol: )

[Edited on 13-08-2014 by A2H GO]


ed

posted on 13th Aug 14 at 16:29

MVC in JavaScript seems pretty complex - I've been trying to get something up and running use Ember and it seems way more complicated than any of the PHP stuff I do.


gooner_47

posted on 13th Aug 14 at 11:46

quote:
Originally posted by ed
If you're doing MVC style programming then you'd be doing some proper OOP. Using the biology example, you'd probably have an Animal model.

MVC in JS is pretty specialist stuff though, and a bit of a pain in the arse.


I'm just getting to this now... I've been following this "course":

http://javascriptissexy.com/how-to-learn-javascript-properly/

Down in Week 7 it says to learn Backbone.js. I haven't actually gone through that section of it yet, but just reading articles about that and other MVC frameworks, tricky concept for me to get my head around. I'm sure it'll become clearer as I actually work through examples.


DaveyLC

posted on 13th Aug 14 at 07:52

quote:
Originally posted by Laney
quote:
Originally posted by DaveyLC
That's a really complex way of doing it.. TUser.Privilages would be better.. No need to get carried away with inheritance when normalisation will suffice.


I apologise.


Dont get me wrong I'm not trying to be an arse, its refreshing to see people actually considering objects these days :D so many programmers are just happy working with events and settings it makes baby Jesus cry.


Laney

posted on 12th Aug 14 at 20:23

quote:
Originally posted by DaveyLC
That's a really complex way of doing it.. TUser.Privilages would be better.. No need to get carried away with inheritance when normalisation will suffice.


I apologise.


DaveyLC

posted on 11th Aug 14 at 19:36

quote:
Originally posted by Laney
Would something like this be a bit more useful?

code:

class User
def login
...
return "Login successful"
end
end

class AdminUser < User
...
def is_admin
return true
end
end

class ClientAdminUser < AdminUser
...
def can_edit
return false
end
end

class SuperAdminUser < AdminUser
...
def can_edit
return true
end
end

@client = ClientAdminUser.new
puts @client.login # "Login successful"
puts @client.can_edit? # false

@super_admin = SuperAdminUser.new
puts @super_admin.login # "Login successful"
puts @super_admin.can_edit? # true




That's a really complex way of doing it.. TUser.Privilages would be better.. No need to get carried away with inheritance when normalisation will suffice.


ed

posted on 11th Aug 14 at 19:31

If you're doing MVC style programming then you'd be doing some proper OOP. Using the biology example, you'd probably have an Animal model.

MVC in JS is pretty specialist stuff though, and a bit of a pain in the arse.


AndyKent

posted on 11th Aug 14 at 18:24

I've never used it for web apps.

For programs where you are handling larger data sets it is useful to break down the information into manageable chunks.

For example, in the past I wrote an application to handle betting via betfair.

When looking at a particular match I would take the data they issue via their API and parse it into my own types to streamline data handled internally within the app.

For example, a type being a football match, a sub type being data about what has happened in the match etc.

I can't see the same need to handle large amounts of data in a web app (since it will be stored by name in a database)


Laney

posted on 11th Aug 14 at 11:03

Would something like this be a bit more useful?

code:

class User
def login
...
return "Login successful"
end
end

class AdminUser < User
...
def is_admin
return true
end
end

class ClientAdminUser < AdminUser
...
def can_edit
return false
end
end

class SuperAdminUser < AdminUser
...
def can_edit
return true
end
end

@client = ClientAdminUser.new
puts @client.login # "Login successful"
puts @client.can_edit? # false

@super_admin = SuperAdminUser.new
puts @super_admin.login # "Login successful"
puts @super_admin.can_edit? # true


DaveyLC

posted on 10th Aug 14 at 14:18

quote:
Originally posted by gooner_47
I was just looking for some more realistic scenarios for using inheritance in an average website.


Well a 'user' object would be one example if you are using any sort of authentication.. then 'session'.


Ian

posted on 10th Aug 14 at 14:07

See this is why I hate OO


DaveyLC

posted on 10th Aug 14 at 12:38

Its an example.. Your objects and classes will be subjective depending on what YOU want to achieve.


gooner_47

posted on 10th Aug 14 at 09:24

Thanks. Nah I get that completely, I do understand inheritance.

My point was, when is a web application you're writing ever going to deal with animals and biology? :o

I was just looking for some more realistic scenarios for using inheritance in an average website.


DaveyLC

posted on 8th Aug 14 at 20:56

Not really because JavaScript technically isn't OO.. You can define classes but its not strictly OO.

Biology is a great example of OO, inheritance and abstract classes.

First of all you need to understand Types, a type defines an object and a type can be inherited and modified to create a new Type and therefore new objects.

You could say TAnimal is a type and TMonkey inherits TAnimal..

TMonkey would have its own properties that are only relevant to TMonkey and TAnimal would have properties that are relevant to all descendants.

So to make a monkey object we would do:

monkey = new TMonkey

But we can also pass TMonkey as TAnimal (because TAnimal is an ancestor of TMonkey).

function detectAnimal(animal: TAnimal)
{
if (animal is TMonkey) print('ITS A MONKEY');
else if (animal is TMouse) print('ITS A MOUSE');
else if (animal is TElephant) print('ITS A ELEPHANT;);
else print('no fucking idea!');
}


Your objects can have infinite levels of inheritance.

TCat could inherit TAnimal but TDomesticCat could inherit TCat and so on..


I've probably just confused you even more now :D

[Edited on 08-08-2014 by DaveyLC]


ed

posted on 7th Aug 14 at 17:33

jQuery uses objects.


gooner_47

posted on 7th Aug 14 at 10:36

OK, so I understand the concept. Fine with that. But all the examples in courses/tutorials are for things like "shapes" or "fruit".

Anyone got any real world examples of when you might use classes (in my case in client-side Javascript)?

Ta