Introduction to Object-oriented Programming

Slides:



Advertisements
Similar presentations
INHERITANCE BASICS Reusability is achieved by INHERITANCE
Advertisements

Object Oriented Programming Chapter 7 Programming Languages by Ravi Sethi.
OBJECT-ORIENTED PROGRAMMING CONCEPTS (Review). What is an Object? What is an Object? Objects have states and behaviors. Example: A dog has states - color,
EEC-681/781 Distributed Computing Systems Java Tutorial Wenbing Zhao Cleveland State University
OOP in Java Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
OOP in Java Fawzi Emad Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
INTRODUCTION TO JAVA PROGRAMMING Chapter 1. What is Computer Programming?
Object Based Programming. Summary Slide  Instantiating An Object  Encapsulation  Inheritance  Polymorphism –Overriding Methods –Overloading vs. Overriding.
Introduction to Object Oriented Programming. Object Oriented Programming Technique used to develop programs revolving around the real world entities In.
Chapter 6 Understanding the Structure of an Application: Procedures, Modules, and Classes.
Programming in Java Unit 2. Class and variable declaration A class is best thought of as a template from which objects are created. You can create many.
Programming Pillars Introduction to Object- Oriented Programming.
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.
Chapter 10 Classes and Objects In-Depth. Chapter 10 A class provides the foundation for creating specific objects, each of which shares the general attributes,
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.
 Objects versus Class  Three main concepts of OOP ◦ Encapsulation ◦ Inheritance ◦ Polymorphism  Method ◦ Parameterized ◦ Value-Returning.
Chapter 3 Introduction to Classes and Objects Definitions Examples.
JAVA Programming (Session 4) “When you are willing to make sacrifices for a great cause, you will never be alone.” Instructor: รัฐภูมิ เถื่อนถนอม
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Programming Logic & Design Second Edition by Tony Gaddis.
Classes, Interfaces and Packages
By : Robert Apeldorn. What is OOP?  Object-oriented programming is a programming paradigm that uses “objects” to design applications and computer programs.
Object-Oriented Programming: Inheritance and Polymorphism.
Author: DoanNX Time: 45’.  OOP concepts  OOP in Java.
 Description of Inheritance  Base Class Object  Subclass, Subtype, and Substitutability  Forms of Inheritance  Modifiers and Inheritance  The Benefits.
Java Programming: Guided Learning with Early Objects Chapter 9 Inheritance and Polymorphism.
Advanced Programming in Java
Object Oriented Programming
OOP: Encapsulation &Abstraction
Object-Oriented Programming Concepts
The Basics of OOP Design
Inheritance ITI1121 Nour El Kadri.
IS 350 Application Structure
University of Central Florida COP 3330 Object Oriented Programming
7.1 What Is An Object Object-oriented program - Description or simulation of application Object-oriented programming is done by adopting or extending an.
Objects as a programming concept
Classes and OOP.
Microsoft Visual Basic 2005: Reloaded Second Edition
Review: Two Programming Paradigms
Classes & Objects.
Advanced Programming in Java
University of Central Florida COP 3330 Object Oriented Programming
Week 4 Object-Oriented Programming (1): Inheritance
Object-Oriented Programming: Classes and Objects
HIGHLEVEL REVIEW Chapter 9 Objects and Classes
Creating and Using Classes
Can perform actions and provide communication
Can perform actions and provide communication
Corresponds with Chapter 7
Lecture 22 Inheritance Richard Gesick.
Object-Oriented Programming
Interfaces.
Advanced Programming Behnam Hatami Fall 2017.
Object Oriented Programming
Can perform actions and provide communication
Object-Oriented Programming
Java Programming, Second Edition
Classes, Objects, Methods and Strings
Object-Oriented Programming: Classes and Objects
Tonga Institute of Higher Education
Object-Oriented Programming: Inheritance and Polymorphism
Object-Oriented Programming
CPS120: Introduction to Computer Science
Final and Abstract Classes
Object-Oriented Programming
Chapter 11 Inheritance and Encapsulation and Polymorphism
Topics OOP Review Inheritance Review Abstract Classes
Chapter 7 Objects and Classes
CSG2H3 Object Oriented Programming
Presentation transcript:

Introduction to Object-oriented Programming

Introduction Classes and class relationships are defined using UML Class diagrams These classes must be implemented Any OOP language can be used Visual Basic C# Java C++

Key Terms (Programming Object) Programming objects are designed to mimic real-world objects Television set / DVD Objects have two important characteristics State: Current data about the object A dog has a name, color, etc… Behavior: Things the object can do A dog can bark, fetch, sit, etc.., The text boxes and buttons with which you are familiar are programming objects

Key Terms (Class) A class is a template or building block for an object We say that an object is an instance of a class We create several bicycles from the same template

Key Terms (Inheritance) Some classes have share characteristics with other classes Mountain bikes, road bikes, etc… all have shared characteristics OOP allows us to inherit state and behavior from other classes The parent classes is called the superclass The derived class is called the subclass

Key Terms (Interface) Here, we are not referring to user interface We refer to the methods and properties of a class that are exposed to the outside world In its most common form, an interface is a group of related methods with empty bodies Classes can then implement an interface

Key Terms (Package) A package is a namespace that organizes a set of related classes and interfaces The Java platform itself is made up of many different packages that you can use In fact, Android uses its own set of Java packages

Benefits of OOP Modularity: Objects are generally independent of other objects Information hiding: The internal implementation of an object is hidden from the outside world Implementation vs. interface Code re-use: Objects can be reused by many other programs

Declaring a Class Classes are declared inside of a class block Properties and methods appear inside of the class block

Declaring a Class (Example 1) Declare a class named Bicycle class Bicyle { }

Access Modifiers (public) public members are globally accessible and available to other assemblies (components) Globally available within the component too Note that Intellisense technology will display exposed members Members of the .NET Framework class library are public for example

Access Modifiers (private) private members are part of the implementation They are exposed only to the class containing the declaration Private members are not visible to other components Private members are not visible to other classes

Access Modifiers (protected) Protected members can only be accessed from their own package

Declaring a Method (Introduction) Remember that methods perform an action In C#, methods are nothing more than procedures These are the same procedures that you have used before

Declaring a Method (Example) Create a method named Area public class Circle { public double Area(double argRadius) return 3.14 * radius * radius; }

Constructors (Introduction) A constructor is a procedure having the same name as the class The declaration looks like a method but has no return type Constructors may accept 0 or more arguments For example, the StreamReader constructor accepts a file name as its argument The constructor executes automatically when the developer creates a class instance A constructor is never called directly

Constructor (Example) Create a constructor to increment an instance counter public Circle() { CallCount++; }

Static Members (Introduction) By default, members are instance members One instance exists for each class instance Think of a TextBox. One instance of the Text property exists for each control instance static members belong to the type so one copy exists for all class instances Declare shared members with the static keyword

Static Members (1) You need not create a class instance to reference a static member The members of the System.Math class are static, for example Only one data copy of static members exist regardless of the instance count Include the static keyword in variable or procedure declarations

Why? Static Members (2) Shared members cannot operate on instance data Instance members can operate with shared data Why?