Download presentation
Presentation is loading. Please wait.
Published byMiles Foster Modified over 8 years ago
1
CPRG 215 Introduction to Object-Oriented Programming with Java Module 3- Introduction to Object Oriented Programming concepts Topic 3.1 Fundamental Concepts Produced by Harvey Peters, 2008 Copyright SAIT
2
Please review the following sections in your textbook Core Java, Volume I–Fundamentals, Eighth Edition By Cay S. Horstmann & Gary Cornell Chapter 4 - Objects and Classes Introduction to Object-Oriented Programming Using Predefined Classes Defining Your Own Classes Static Fields and Methods Method Parameters CPRG 215 Module 3.1- Fundamental Concepts Copyright SAIT
3
Introduction to Objects History –variables treated as isolated values –led to the need for many variable names in code –ignores associations between variables year, month, day -- all part of date –Code required to work with the data was duplicated in every program that used the data, and often varied from one program to another Topic 3.1.1 CPRG 215 Module 3.1- Fundamental Concepts Copyright SAIT
4
Introduction to Objects Object is a container for data and the logic that is needed to maintain the data Objects correspond to actual things that people use in their work Methods correspond to actual tasks that are done to store and maintain data used in the work Topic 3.1.1 CPRG 215 Module 3.1- Fundamental Concepts Copyright SAIT
5
Instantiating Objects Creating an Object –Declaring primitive types allocates memory space int x; –Declaring nonprimitive (object) types does not allocate memory space MyObject newobj1; –Declared variables are not the data itself, but references (or pointers) to the object that contains the data Topic 3.1.2 CPRG 215 Module 3.1- Fundamental Concepts Copyright SAIT
6
Instantiating Objects Instantiation (creating an instance): –Before using the variable we must allocate the storage space MyDate myBirthday; myBirthday = new MyDate(); –What this means is: given a class Xxxx, we can call “new Xxxx()” to create as many objects as we need, each with its own memory space Class Instantiation Object Topic 3.1.2 CPRG 215 Module 3.1- Fundamental Concepts Copyright SAIT
7
Object Orientation Theory Key features of OOP languages –Abstraction –Encapsulation –Polymorphism –Inheritance Topic 3.1.3 CPRG 215 Module 3.1- Fundamental Concepts Copyright SAIT
8
Object Orientation Theory Abstraction –Identify the common features of a group of objects and build a class –Create subclasses to add-on specialized features Topic 3.1.3 CPRG 215 Module 3.1- Fundamental Concepts Copyright SAIT
9
Object Orientation Theory Encapsulation –hides the implementation details (internal operations) of a class –forces the user to use an interface to access data (like a doorway) –Data Hiding public vs. private access –You can’t help yourself to private data, but you can ask a public method for it Topic 3.1.3 CPRG 215 Module 3.1- Fundamental Concepts Copyright SAIT
10
Object Orientation Theory Polymorphism –Subclassing takes an abstract class and creates a more specialized version of it, adding features Employee is a special type of person FullTime is a special type of Employee Manager is a special type of FullTime –object can behave as if it were a higher-level object A Manager is a FullTime and an Employee, and a Person Person Employee FullTime Manager Topic 3.1.3 CPRG 215 Module 3.1- Fundamental Concepts Copyright SAIT
11
Object Orientation Theory Inheritance –A subclass inherits the parent’s methods and properties –Java only allows one parent per class But the parent can have a parent, and so on, forming a chain of parent/child relationships called a hierarchy Topic 3.1.3 CPRG 215 Module 3.1- Fundamental Concepts Copyright SAIT
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.