Chapter 6 Object-Oriented Java Script JavaScript, Third Edition.

Slides:



Advertisements
Similar presentations
1 Classes and Objects in Java Basics of Classes in Java.
Advertisements

Understand and appreciate Object Oriented Programming (OOP) Objects are self-contained modules or subroutines that contain data as well as the functions.
Java Programming, 3e Concepts and Techniques Chapter 5 Arrays, Loops, and Layout Managers Using External Classes.
© 2006 Pearson Addison-Wesley. All rights reserved4-1 Chapter 4 Data Abstraction: The Walls.
C# Programming: From Problem Analysis to Program Design1 Advanced Object-Oriented Programming Features C# Programming: From Problem Analysis to Program.
ASP.NET Programming with C# and SQL Server First Edition
JavaScript, Third Edition
ASP.NET Programming with C# and SQL Server First Edition
Chapter 13: Object-Oriented Programming
Introduction to Classes and Objects CS-2303, C-Term Introduction to Classes and Objects CS-2303 System Programming Concepts (Slides include materials.
OOP in Java Fawzi Emad Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
PHP Programming with MySQL Slide 11-1 CHAPTER 11 Developing Object-Oriented PHP.
1.11 Introduction to OOP academy.zariba.com 1. Lecture Content 1.What is OOP and why use it? 2.Classes and objects 3.Static classes 4.Properties, fields.
Object Oriented Programming
Object Based Programming. Summary Slide  Instantiating An Object  Encapsulation  Inheritance  Polymorphism –Overriding Methods –Overloading vs. Overriding.
Using Object-Oriented JavaScript CST 200- JavaScript 4 –
Programming Languages and Paradigms Object-Oriented Programming.
CSM-Java Programming-I Spring,2005 Introduction to Objects and Classes Lesson - 1.
Introduction to Classes, Objects, Methods and Attributes Lecture # 2.
Chapter 5 Java Script And Forms JavaScript, Third Edition.
Chapter 8 More Object Concepts
CSM-Java Programming-I Spring,2005 Objects and Classes Overview Lesson - 1.
Objectives In this chapter, you will:
An Object-Oriented Approach to Programming Logic and Design
Introduction to Object Oriented Programming. Object Oriented Programming Technique used to develop programs revolving around the real world entities In.
Tutorial 2 Variables and Objects. Working with Variables and Objects Variables (or identifiers) –Values stored in computer memory locations –Value can.
An Introduction to Java Chapter 11 Object-Oriented Application Development: Part I.
JavaScript, Fourth Edition
Chapter 6 OOP: Creating Object-Oriented Programs Programming in C#.NET © 2003 by The McGraw-Hill Companies, Inc. All rights reserved.
1 Classes and Objects in C++ 2 Introduction Java is a true OO language and therefore the underlying structure of all Java programs is classes. Anything.
1 Classes and Controls CE-105 Spring 2007 By: Engr. Faisal ur Rehman.
Advanced Object- Oriented Programming Programming Right from the Start with Visual Basic.NET 1/e 14.
Object Based Programming Chapter 8. 2 In This Chapter We will learn about classes Garbage Collection Data Abstraction and encapsulation.
1 Chapter 8 – Classes and Object: A Deeper Look Outline 1 Introduction 2 Implementing a Time Abstract Data Type with a Class 3 Class Scope 4 Controlling.
Object-Oriented Design Simple Program Design Third Edition A Step-by-Step Approach 11.
Data Structures Using C++ 2E1 Inheritance An “is-a” relationship –Example: “every employee is a person” Allows new class creation from existing classes.
An Object-Oriented Approach to Programming Logic and Design Chapter 3 Using Methods and Parameters.
 Classes in c++ Presentation Topic  A collection of objects with same properties and functions is known as class. A class is used to define the characteristics.
Chapter 6 OOP: Creating Object-Oriented Programs Programming In Visual Basic.NET.
Visual C# 2012 for Programmers © by Pearson Education, Inc. All Rights Reserved.
Chapter 10 Defining Classes. The Internal Structure of Classes and Objects Object – collection of data and operations, in which the data can be accessed.
Chapter 2: Variables, Functions, Objects, and Events JavaScript - Introductory.
Programming with Java © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 1 McGraw-Hill/Irwin Chapter 5 Creating Classes.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 26 - Java Object-Based Programming Outline 26.1Introduction.
Introduction to Java Chapter 7 - Classes & Object-oriented Programming1 Chapter 7 Classes and Object-Oriented Programming.
Classes. Constructor A constructor is a special method whose purpose is to construct and initialize objects. Constructor name must be the same as the.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Objects and Classes.
Liang, Introduction to Java Programming, Fifth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 6 Objects and Classes.
Introduction to Object-Oriented Programming Lesson 2.
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Programming Logic & Design Second Edition by Tony Gaddis.
Introduction to Classes, Objects, Methods and Attributes Lecture # 5.
CS 5JA Introduction to Java Pop Quiz Define/Explain encapsulation. In object-oriented programming, encapsulation refers to the grouping of data and the.
Classes, Interfaces and Packages
Chapter 10 Developing Object-Oriented PHP. 2 Objectives In this chapter, you will: Study object-oriented programming concepts Use objects in PHP scripts.
Object orientation and Packaging in Java Object Orientation and Packaging Introduction: After completing this chapter, you will be able to identify.
CSCI 171 Presentation 15 Introduction to Object–Oriented Programming (OOP) in C++
Programming Fundamentals1 Chapter 7 INTRODUCTION TO CLASSES.
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Programming Logic & Design Second Edition by Tony Gaddis.
Object Based Programming Chapter 8. 2 Contrast ____________________ Languages –Action oriented –Concentrate on writing ________________ –Data supports.
CE-105 Spring 2007 By: Engr. Faisal ur Rehman
Introduction to Object-oriented Programming
JavaScript, Sixth Edition
Chapter 3: Using Methods, Classes, and Objects
Section 11.1 Class Variables and Methods
Chapter 11 Developing Object-Oriented PHP PHP Programming with MySQL Revised by A. Philipp – Spring 2010 (Rev SP’11)
Object Based Programming
Object Oriented Programming in java
Final and Abstract Classes
Chapter 7 Objects and Classes
Introduction to Classes and Objects
Presentation transcript:

Chapter 6 Object-Oriented Java Script JavaScript, Third Edition

2 Objectives Study object-oriented programming Learn about the built-in JavaScript objects Work with the Array, Date, Math, and Number objects Define custom JavaScript objects

JavaScript, Third Edition 3 Introduction to Object-Oriented Programming Object-oriented programming allows you to reuse code without having to copy or recreate it

JavaScript, Third Edition 4 Reusable Software Object-oriented programming (OOP): –Refers to the creation of reusable software objects that can be easily incorporated into multiple programs Object: –Specifically refers to programming code and data that can be treated as an individual unit or component

JavaScript, Third Edition 5 Reusable Software (Cont.) Data: –Refers to information contained within variables or other types of storage structures Objects can range from simple controls such as a button, to entire programs such as a database application

JavaScript, Third Edition 6 Reusable Software (Cont.) Popular object-oriented programming languages include C++, Java, and Visual Basic Using any of these or other object-oriented languages: –Programmers can create objects themselves or use objects created by other programmers

JavaScript, Third Edition 7 Encapsulation Objects are encapsulated: –All code and required data are contained within the object itself Encapsulation: –Places code inside what programmers like to call a “black box” –When an object is encapsulated, you cannot see “inside” it—all internal workings are hidden

JavaScript, Third Edition 8 Encapsulation (Cont.) The code (methods and statements) and data (variables and constants) contained in an encapsulated object are accessed through an interface Interface: –Represents elements required for a source program to communicate with an object

JavaScript, Third Edition 9 Encapsulation (Cont.) The principal of information hiding states that: –Any class members that other programmers do not need to access or know about should be hidden

JavaScript, Third Edition 10 Encapsulation (Cont.) Encapsulation prevents other programmers from: –Accidentally introducing a bug into a program –Stealing the code and claiming it as their own

JavaScript, Third Edition 11 Encapsulation (Cont.)

JavaScript, Third Edition 12 Classes In object-oriented programming: –Code, methods, attributes, and other information that make up an object are organized into classes Class: –Template, or blueprint, that serves as the basis for new objects Instance: –Object that has been created from an existing class Called instantiating the object

JavaScript, Third Edition 13 Classes (Cont.) A particular instance of an object inherits its methods and properties from a class: –It takes on the characteristics of the class on which it is based

JavaScript, Third Edition 14 Built-in JavaScript Classes

JavaScript, Third Edition 15 Instantiating an Object You can use some of the built-in JavaScript objects directly in your code Other objects require you to instantiate a new object

JavaScript, Third Edition 16 Garbage Collection Refers to cleaning up, or reclaiming, memory that is reserved by a program JavaScript knows when a program no longer needs a variable or object –Automatically cleans up the memory

JavaScript, Third Edition 17 Array Class The Array class creates new array objects When creating an array using the Array() constructor, an object from the Array class is instantiated In addition to the Array() constructor, the Array class contains: –Methods and properties for manipulating the elements of an array

JavaScript, Third Edition 18 Array Class Methods

JavaScript, Third Edition 19 The Length Property Returns the number of elements in an array You append the length property to the name of the array you want to sort using the following syntax: array_name.length;

JavaScript, Third Edition 20 Date Class Contains methods and properties for manipulating the date and time The Date object allows you to use the current date and time in your JavaScript programs You create a new instance of the Date class using the syntax var dateObject = new Date();

JavaScript, Third Edition 21 Date Class (Cont.)

JavaScript, Third Edition 22 Number Class Contains methods for manipulating numbers and properties that contain static values representing some of the numeric limitations in the JavaScript language

JavaScript, Third Edition 23 Number Class Methods

JavaScript, Third Edition 24 Number Class Properties

JavaScript, Third Edition 25 Math Class The Math class contains methods and properties for performing mathematical calculations in your programs

JavaScript, Third Edition 26 Math Class Methods

JavaScript, Third Edition 27 Math Class Methods (Cont.)

JavaScript, Third Edition 28 Math Class Properties

JavaScript, Third Edition 29 Custom JavaScript Objects JavaScript is not a true object-oriented programming language: –Base objects in your programs on built-in JavaScript classes such as the Array and Date objects –However, you cannot create your own classes in JavaScript –You can define your own custom objects using a constructor function

JavaScript, Third Edition 30 Constructor Function A function used as the basis for a custom object JavaScript objects inherit all the variables and statements of the constructor function on which they are based Any JavaScript function can serve as a constructor

JavaScript, Third Edition 31 Properties To add a property to a constructor function: –You must add a statement to the function body that uses the this keyword with the following syntax: this.property_name = value; –In the case of a custom JavaScript object, the this keyword refers to the object that calls the constructor function

JavaScript, Third Edition 32 Methods You can create a function that will be used as an object method: –By referring to any object properties using the this reference

JavaScript, Third Edition 33 The prototype Property The prototype property is a built-in property: –Specifies the constructor from which an object was extended

JavaScript, Third Edition 34 Chapter Summary Object-Oriented programming (OOP): –Refers to the creation of reusable software objects that can be easily incorporated into another program Components: –Reusable software objects Object: –Programming code and data that can be treated as an individual unit or component

JavaScript, Third Edition 35 Chapter Summary (cont.) Objects are encapsulated: –All code and required data are contained within the object itself Interface : –Represents elements required for a source program to communicate with an object The principal of information hiding: –States that any class members that other programmers do not need to access or know about should be hidden

JavaScript, Third Edition 36 Chapter Summary (cont.) In object-oriented programming: –Code, methods, attributes, and other information that make up an object are organized using classes An instance: –Object created from an existing class An object inherits, or takes on, the characteristics of the class on which it is based The Date class: –Contains methods and properties for manipulating the date and time

JavaScript, Third Edition 37 Chapter Summary (cont.) The Number class: –Contains methods for manipulating numbers and properties that The this keyword: –Refers to the current object The prototype property: –Built-in property that specifies the constructor from which an object was extended