5. Problem:
Build an employee database
What attributes do we want to keep?
Employee Name: e.g. Sylvester Stallone
Employee Address: e.g. (Beverly Hills, California, USA)
Employee Id: e.g. 127001
Employee Salary: e.g. $1000000
What operations do we want?
What other things can we do?
3/28/2013 4Let’s Code: Session 3
6. Problem:
Build an employee database
What attributes do we want to keep?
What operations do we want?
Get Employee Name
Get Employee id
Change Salary
Give 100$ bonus if address is in Beverly Hills
Add a new information about the employee
Add info about speciality e.g. “Mind Blowing Action Movies”
What else can we do?
3/28/2013 5Let’s Code: Session 3
7. Create an Employee:
Which data structure to use ??
Lets use dict
Attributes:
3/28/2013 6Let’s Code: Session 3
Attribute Type Example
name string “Sylvester Stallone”
address tuple (“Beverly Hills”,”CA”,”USA”)
id int 127001
salary int 1000000
8. Create an Employee:
Functions:
Now let us extend this to a database >
Non-object oriented way
Object Oriented way
3/28/2013 7Let’s Code: Session 3
Actions Example Logic
get_employee_name “Sylvester Stallone”
get_employee_id 127001
change_salary if(address[0] == “Beverly Hills”): salary += 100
Add_new_info Add attribute: Speciality
9. Basic philosophy
A “container” to hold attributes and operations realted
to those attributes in one single place!!
Anybody having C background?? – lets start of by
thinking of struct: container to hold data
How about if we have some funcitons?
What you ask about the syntax?? ok so be it
3/28/2013 8Let’s Code: Session 3
11. 3/28/2013 10Let’s Code: Session 3
Example of a class:
Special notes : self
Looking a bit deepr: where are these created
12. Some other concepts
Adding attributes
Deleting instances
Control the delete operation
3/28/2013 11Let’s Code: Session 3
13. Problem:
Build an employee database
What attributes do we want to keep?
What operations do we want?
What else can we do?
Extend definitons of Employee
Multiple Inheritance
3/28/2013 12Let’s Code: Session 3
14. Creating a “super Employee”
Use attributes the same as Employee but add a new
attribute: position
Way out : Inheritance
3/28/2013 13Let’s Code: Session 3
15. Change the bonus function
Give 100$ more if CEO
Way out function overloading
3/28/2013 14Let’s Code: Session 3
16. Multiple Inheritance
Another “base class”
Creating the super Duper employee
3/28/2013 15Let’s Code: Session 3
18. A Big thanks to the sponsor for this session:
And best of all!! Akamai is currently recruiting for
summer interns. All positions are listed at
jobs.akamai.com or you can send resumes directly to
gkoenig@akamai.com
3/28/2013 17Let’s Code: Session 3