Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

CSIS 110 Lecture 9: Mail System Project and this Keyword - Prof. Brian F. Hanks, Study notes of Javascript programming

In this lecture, students are instructed to finish reading chapter 3 and take a quiz on constructor overloading, indenting with if statements, and the mail system project. The lecture covers the mailitem class, focusing on constructor name overloading and the use of the 'this' keyword. Students are encouraged to work on lab assignments with a partner and modify the mailitem and mailclient classes to include a subject for new messages.

Typology: Study notes

Pre 2010

Uploaded on 08/05/2009

koofers-user-f8a-1
koofers-user-f8a-1 🇺🇸

5

(1)

10 documents

1 / 3

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CSIS 110 – Lecture 9
Reading: finish chapter 3
Quiz Results
Mean: 21.5 Median: 22 Max: 25
Distribution: <17.5: 1 17.5 – 19.5: 1 20 – 22: 7 22.5 - 24.5: 5 25: 3
Last Time
- Constructor overloading
- Internal and External method calls
oInternal: Method in same class. Call it implicitly on the current object.
oExternal: Method in a different class. Call it using an object (not the class)
Discuss indenting w/ if statements.
Mail-System
Show how the mail-system project works.
Now, go ahead and open this project and try it yourselves.
There are three classes in this project: MailItem, MailClient, and MailServer
- MailItem is fairly simple
- We’ll look at MailClient in more detail
- MailServer is more complex – I won’t be talking about it in detail. We can see
that it works to send messages (as MailItems) from one MailClient to another. We
don’t HAVE to know how it works – another benefit of abstraction.
The this keyword
Let’s look at the MailItem class. Look at the constructor – is there something new?
this.from = from;
What kind of statement is this?
It’s an assignment – it assigns the value of the LHS (from) to the RHS (this.from).
What’s going on? What is the name of the formal parameter in the constructor? What is
the name of the instance variable? Oops! They have the same name! This is called name
overloading.
So, while constructor is executing, there are 6 variables [Draw pix].
pf3

Partial preview of the text

Download CSIS 110 Lecture 9: Mail System Project and this Keyword - Prof. Brian F. Hanks and more Study notes Javascript programming in PDF only on Docsity!

CSIS 110 – Lecture 9

Reading: finish chapter 3 Quiz Results Mean: 21.5 Median: 22 Max: 25 Distribution: <17.5: 1 17.5 – 19.5: 1 20 – 22: 7 22.5 - 24.5: 5 25: 3 Last Time

  • Constructor overloading
  • Internal and External method calls o Internal: Method in same class. Call it implicitly on the current object. o External: Method in a different class. Call it using an object (not the class) Discuss indenting w/ if statements. Mail-System Show how the mail-system project works. Now, go ahead and open this project and try it yourselves. There are three classes in this project: MailItem, MailClient, and MailServer
  • MailItem is fairly simple
  • We’ll look at MailClient in more detail
  • MailServer is more complex – I won’t be talking about it in detail. We can see that it works to send messages (as MailItems) from one MailClient to another. We don’t HAVE to know how it works – another benefit of abstraction. The this keyword Let’s look at the MailItem class. Look at the constructor – is there something new? this.from = from; What kind of statement is this? It’s an assignment – it assigns the value of the LHS (from) to the RHS (this.from). What’s going on? What is the name of the formal parameter in the constructor? What is the name of the instance variable? Oops! They have the same name! This is called name overloading. So, while constructor is executing, there are 6 variables [Draw pix].

When we refer to the name from in the constructor body, which one does it mean? As it turns out, the formal parameter, because it is the ‘closer’ declaration. [Discuss scope here] So, how do we refer to the field from the statement body? We use the keyword this – this is a reference to the current object. So, the expression this.from refers to the from field of the current object. Writing this.from = from; can be thought of as field named from = parameter named from; So, we can give the field and the formal parameter the same name, and we have a way to access them both. Why would we want to? Because sometimes the name is just a good name, and makes more sense than anything else! Partners Jeremy/Paul Hilary/Katherine Ileah/Crystal Justin/Greg Brian/Janet Kerry/Jake Alone – This applies to out of class assignments only. Work with a partner on labs! Josh Tah Lee Jared G Jarred S Nick