02Geek HTML5 and JavaScript, TypeScript, React, Flash, ActionScript online School
Previous VideoNext Video

Static Classes

What is a static class? Why do we use them and how do we take advantage of there capabilities. Static classes aren't used to create objects and instead are directly accessed through the class(many classes can have some static properties).

Video Transcript

00:00Talking about static classes just for a minute.
00:02What are static classes?
00:03Static classes or, and I'm just defining static
00:06because really that's really where the term comes
00:09for lacking in movement, action or change.
00:11The idea of a static class is actually a class
00:13that doesn't turn into an object.
00:15And how do you create a class that doesn't turn
00:17into an object in ActionScript 3?
00:19It's basically you add the word static
00:21to the functions and properties.
00:23Now what does that give you?
00:25So there aren't used, basically these classes
00:28aren't used to create objects
00:29and instead they're directly accessed
00:31through the class itself.
00:32Many classes can have some static properties
00:35and not be completely static classes.
00:38So basically for example, a very, very good example
00:42of a static class is the math class.
00:44The math class is really just a class
00:46that has a lot of different properties and methods.
00:48There is no need for a specific object for it.
00:50It doesn't need a reference.
00:52But the math class has access
00:53to all these type of cool features, let's say,
00:56apps that enables us to get an absolute value
01:01from a number and so on and so forth.
01:03Executive, the math class.
01:06So the idea of classes like this
01:08are classes that just don't need a reference.
01:10They don't need a this.
01:11They don't need to have a specific item
01:14to store information and have properties
01:16and so on and so forth.
01:17They don't have a need to actually have an object.
01:22So all they really need is a class, so static class.
01:25Usually programmers don't build static classes per se.
01:29A lot of times they would do is create a singleton.
01:32Most of the time when you're gonna find a static class
01:34as a full class, you would usually find that
01:37in the libraries of your programming language
01:41such as the math class.
01:42And you would probably most of the time
01:44try to work with singletons
01:45whenever you wanna create something
01:46that has one instance of.
01:49Because static classes are just run
01:51not as fast as actual objects
01:56for technical reasons in many languages.
02:00Well, I'm trying to think what else I wanna say about this.
02:02That's really all I have to say about that.
02:03The only thing else I could add to that
02:04is sometimes you wanna create only one static function
02:07or a static property in an element.
02:10It doesn't have to be everything static.
02:11You could just define the column B function
02:13and just write your static.
02:15Now the column B is not part of the object
02:17that will be created,
02:18but column B is actually part of the class.
02:20So whenever we wanna interact with it,
02:22we would type payphone dot
02:25and then the name of that static function
02:27which then would not be inside of the instance
02:29when we would create a specific instance, okay?
02:32Now, if this was a little bit too much
02:34and you don't really know what I'm talking about
02:36at this stage, I would recommend going back
02:38to this after you play around with object
02:40or into the programming a little bit more.

Ready to Level Up Your Skills?

Join thousands of learners on 02GEEK and start your journey to becoming a coding expert today!

Enroll Now for Free!