Presentation is loading. Please wait.

Presentation is loading. Please wait.

Classes CS 401 (an excerpt).

Similar presentations


Presentation on theme: "Classes CS 401 (an excerpt)."— Presentation transcript:

1 Classes CS 401 (an excerpt)

2 Object-Oriented Programming
Real-world objects represented inside “digital” objects Methods interact with and modify objects Classes Blueprints for data Describe how to interact with data Encapsulation All data and operations for an object are together Everything related to that object is encapsulated inside the class Data Abstraction Hide details of how data is stored/represented

3 Example Class: Person What data should be stored in the Person class?

4 Example Class: Person What data should be stored in the Person class?
Name Age Address

5 Example Class: Person What data should be stored in the Person class?
Name Age Address What actions should the Person class allow?

6 Example Class: Person What data should be stored in the Person class?
Name Age Address What actions should the Person class allow? Get the name, set the name Get the age, increment the age Get the address, update the address

7 Designing a Class What data should be stored in the class?
What actions should the class allow? Depend on how class will be used

8 Classes and Objects Classes: Blueprints for data
Define/declare a class List data and actions for the class

9 Classes and Objects Classes: Blueprints for data
Define/declare a class List data and actions for the class Name: Age: Address: Person Class

10 Classes and Objects Classes: Blueprints for data
Define/declare a class List data and actions for the class Objects: Instances of a class Holds values for the data in the blueprint Name: Age: Address: Person Class Name: Age: Address: Zeus 4000 Mt. Olympus Person

11 Classes and Objects Classes: Blueprints for data
Define/declare a class List data and actions for the class Objects: Instances of a class Holds values for the data in the blueprint Reference Variables: Refer to objects Name: Age: Address: Person Class Name: Age: Address: Zeus 4000 Mt. Olympus Person

12 Classes and Objects Classes: Blueprints for data
Define/declare a class List data and actions for the class Objects: Instances of a class Holds values for the data in the blueprint Reference Variables: Refer to objects p = Person("Zeus", 4000, "Mt. Olympus")

13 Classes and Objects Classes: Blueprints for data
Define/declare a class List data and actions for the class Objects: Instances of a class Holds values for the data in the blueprint Reference Variables: Refer to objects p = Person("Zeus", 4000, "Mt. Olympus") Name: Age: Address: Zeus 4000 Mt. Olympus Person

14 Classes and Objects Classes: Blueprints for data
Define/declare a class List data and actions for the class Objects: Instances of a class Holds values for the data in the blueprint Reference Variables: Refer to objects p = Person("Zeus", 4000, "Mt. Olympus") Person ref. var. Name: Age: Address: Zeus 4000 Mt. Olympus Person p

15 Classes and Objects Classes: Blueprints for data
Define/declare a class List data and actions for the class Objects: Instances of a class Holds values for the data in the blueprint Reference Variables: Refer to objects p = Person("Zeus", 4000, "Mt. Olympus") Person ref. var. Name: Age: Address: Zeus 4000 Mt. Olympus Person p

16 Classes and Objects Classes: Blueprints for data
We’ll need to create the Person constructor … more on this later. Classes: Blueprints for data Define/declare a class List data and actions for the class Objects: Instances of a class Holds values for the data in the blueprint Reference Variables: Refer to objects p = Person("Zeus", 4000, "Mt. Olympus") Person ref. var. Name: Age: Address: Zeus 4000 Mt. Olympus Person p

17 Object Independence Objects are independent of each other
zeus = Person("Zeus", 4000, "Mt. Olympus") hades = Person("Hades", 3900, "Underworld") Name: Age: Address: Zeus 4000 Mt. Olympus Person zeus Person ref. var. Name: Age: Address: Hades 3900 Underworld Person hades Person ref. var.


Download ppt "Classes CS 401 (an excerpt)."

Similar presentations


Ads by Google