Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Preview
Start a free Courses trial
to watch this video
That's the System.Object class folks!
This video doesn't have any notes.
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign upRelated Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
To wrap up this part of the course,
let's go back and
0:00
take a look at the list of methods
the system.object provides.
0:03
As we've seen we can override
most of these methods
0:07
with their own implementations.
0:09
We've seen how overwriting ToString
can provide a better conversion
0:11
of objects to string.
0:15
The default implementation
provided by system.object is
0:17
just to print the object's type name.
0:21
We've seen how we can
redefine what it means for
0:23
two objects to be equal by
overriding equals and get hash code.
0:26
There are a couple more methods in
system.object, we haven't looked at yet.
0:31
Finalize is used by
the memory management system,
0:35
also known as the garbage collector.
0:39
You see every time a new
object is created,
0:41
it's stored some place in
the computer's memory.
0:44
We may create lots and
0:47
lots of objects, eventually we don't need
access to some of these objects any more.
0:48
We don't have any way to delete them
from memory and free up that space for
0:54
other objects, so these objects can
just sit in memory taking up space.
0:58
Periodically, .NET memory management
system runs the garbage collector which
1:04
goes through the memory and
1:09
finds objects that aren't being
used by the program anymore.
1:10
It removes them from the memory and
frees up the space.
1:13
We're given the opportunity
to run some final code
1:17
right before the object is removed,
that's the purpose of the finalize method.
1:20
We can override the finalize method and
write whatever code we want there.
1:26
Typically, finalize is
used to close files and
1:30
clean up any other computer resources
that the object may have been using.
1:33
Most of the time we don't need to
think about the finalizer method.
1:37
Writing finalizer methods
is something that is rare,
1:41
so we won't go into it right now.
1:44
The MemberwiseClone method is
exactly what it sounds like.
1:46
It is used to create a copy of an object.
1:50
The method is protected so it's only
accessible from within the subclass.
1:53
But it also can't be overridden by
subclasses because it's not virtual,
1:57
this method is rarely used in practice.
2:02
So that's the system.object class.
2:05
In most cases, we don't interact
with this class directly,
2:08
instead we use it indirectly
through a subclass.
2:12
Because all classes inherit
from system.object,
2:16
we can count on all objects
having these methods.
2:19
This is just one more
example of how polymorphism
2:23
with virtual methods is useful.
2:27
In the next part of this course, we'll
learn about the final basic principle of
2:29
object oriented programming, abstraction.
2:33
We'll learn how C #
supports this principle by
2:36
further extending the tree
house defense game.
2:39
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up