Recap (önemli noktaları yinelemek) from last week Paradigm Kay’s Description Intro to Objects Messages / Interconnections Information Hiding Classes Inheritance.

Slides:



Advertisements
Similar presentations
Based on Java Software Development, 5th Ed. By Lewis &Loftus
Advertisements

Inheritance Java permits you to use your user defined classes to create programs using inheritance.
ITEC200 – Week03 Inheritance and Class Hierarchies.
Object-Oriented PHP (1)
Road Map Introduction to object oriented programming. Classes
Inheritance and Class Hierarchies Chapter 3. Chapter 3: Inheritance and Class Hierarchies2 Chapter Objectives To understand inheritance and how it facilitates.
OOP in Java Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
June 1, 2000 Object Oriented Programming in Java (95-707) Java Language Basics 1 Lecture 3 Object Oriented Programming in Java Language Basics Classes,
7M701 1 Class Diagram advanced concepts. 7M701 2 Characteristics of Object Oriented Design (OOD) objectData and operations (functions) are combined 
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter N - 1 Chapter 13 Polymorphism is-a relationships Interfaces.
Evan Korth New York University Computer Science I Classes and Objects Professor: Evan Korth New York University.
Object-oriented Programming Concepts
Terms and Rules Professor Evan Korth New York University (All rights reserved)
Data Abstraction and Object- Oriented Programming CS351 – Programming Paradigms.
CS 2511 Fall  Abstraction Abstract class Interfaces  Encapsulation Access Specifiers Data Hiding  Inheritance  Polymorphism.
Chapter 10 Classes Continued
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter N - 1 Chapter 13 Polymorphism is-a relationships Interfaces.
1 Chapter 8 Objects and Classes. 2 Motivations After learning the preceding chapters, you are capable of solving many programming problems using selections,
Java Methods By J. W. Rider. Java Methods Modularity Declaring methods –Header, signature, prototype Static Void Local variables –this Return Reentrancy.
Object Oriented Software Development
Inheritance using Java
UFCEUS-20-2 : Web Programming Lecture 5 : Object Oriented PHP (1)
Object-Oriented Programming Concepts
CSM-Java Programming-I Spring,2005 Introduction to Objects and Classes Lesson - 1.
Introduction to Object-oriented programming and software development Lecture 1.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 12 Object-Oriented.
CISC6795: Spring Object-Oriented Programming: Polymorphism.
OBJECT ORIENTED PROGRAMMING CONCEPTS ISC 560. Object-oriented Concepts  Objects – things names with nouns  Classes – classifications (groups) of similar.
Introduction to Object Oriented Programming. Object Oriented Programming Technique used to develop programs revolving around the real world entities In.
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.
An Introduction to Java Chapter 11 Object-Oriented Application Development: Part I.
CSCI-383 Object-Oriented Programming & Design Lecture 13.
CS200 Algorithms and Data StructuresColorado State University Part 4. Advanced Java Topics Instructor: Sangmi Pallickara
Chapter 7 Objects and Classes 1 Fall 2012 CS2302: Programming Principles.
Lecture Set 11 Creating and Using Classes Part B – Class Features – Constructors, Methods, Fields, Properties, Shared Data.
Inheritance - Polymorphism ITI 1121 Nour El Kadri.
Centre for Computer Technology ICT214 Object Oriented Design and Programming Week 02 – Classes, Objects, Instances Richard Salomon and Umesh Patel Centre.
Programming in Java CSCI-2220 Object Oriented Programming.
Chapter 6 Introduction to Defining Classes. Objectives: Design and implement a simple class from user requirements. Organize a program in terms of a view.
Summing Up Object Oriented Design. Four Major Components: Abstraction modeling real-life entities by essential information only Encapsulation clustering.
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.
CS451 - Lecture 2 1 CS451 Lecture 2: Introduction to Object Orientation Yugi Lee STB #555 (816) * Acknowledgement:
COP INTERMEDIATE JAVA Designing Classes. Class Template or blueprint for creating objects. Their definition includes the list of properties (fields)
Design Patterns Software Engineering CS 561. Last Time Introduced design patterns Abstraction-Occurrence General Hierarchy Player-Role.
Inheritance and Class Hierarchies Chapter 3. Chapter 3: Inheritance and Class Hierarchies2 Chapter Objectives To understand inheritance and how it facilitates.
Inheritance and Class Hierarchies Chapter 3. Chapter Objectives  To understand inheritance and how it facilitates code reuse  To understand how Java.
Classes, Interfaces and Packages
Quick Review of OOP Constructs Classes:  Data types for structured data and behavior  fields and methods Objects:  Variables whose data type is a class.
Java Programming, Second Edition Chapter Three Using Methods, Classes, and Objects.
Chapter 7 Classes and Methods III: Static Methods and Variables Lecture Slides to Accompany An Introduction to Computer Science Using Java (2nd Edition)
Author: DoanNX Time: 45’.  OOP concepts  OOP in Java.
5.1 Basics of defining and using classes A review of class and object definitions A class is a template or blueprint for an object A class defines.
OOP Basics Classes & Methods (c) IDMS/SQL News
 Description of Inheritance  Base Class Object  Subclass, Subtype, and Substitutability  Forms of Inheritance  Modifiers and Inheritance  The Benefits.
Classes CS 162 (Summer 2009). Parts of a Class Instance Fields Methods.
 The Object Oriented concepts was evolved for solving complex problems. Object- oriented software development started in the 1980s. Object-oriented design.
Object-Oriented Design
Inheritance and Polymorphism
Chapter 11 Object-Oriented Design
Chapter 3: Using Methods, Classes, and Objects
INTRODUCTION TO OBJECT-ORIENTED PROGRAMMING (OOP) & CONCEPTS
Interfaces.
Advanced Java Programming
Object-Oriented PHP (1)
CSG2H3 Object Oriented Programming
Presentation transcript:

Recap (önemli noktaları yinelemek) from last week Paradigm Kay’s Description Intro to Objects Messages / Interconnections Information Hiding Classes Inheritance public class MammalTester { // will work Mammal mam = new Florist(); // will not work Florist flo = new Mammal(); }

The JVM

Key Aspects of OO Programming Abstraction  just the essentials Composition  building from parts Separation  what vs. how Generalization  finding the common elements

Abstraction "Simplifying to its essentials the description of a real-world entity” Encapsulation

Properties of Good Abstraction Well named Coherent - attributes and behavior that are related and make sense Accurate - attributes and behavior match the entity being modeled Minimal - nothing extraneous Complete - all the attributes and behavior that are necessary Consistency - Operations should be consistent with each other and with respect to names, arguments, return values, and behavior. Decoupled - Different abstractions should not be inter-dependent

Classes “A class is a blueprint, or prototype, that defines the variables and the methods common to all objects of a certain kind." - Java Tutorial In Java, everything is defined in some class

Classes Classes are either defined by the Application Program Interface (API) or are programmer defined data types. Standard Java API classes are organized in packages:  java.lang  java.util ...

Classes There will always be one file for each.class file At least to start, you will find it easiest if you maintain one.java source file for each class

Anatomy of a Java class Package Imports Comments Declaration Fields Constructors Methods

A method is a named sequence of instructions - an action you can request an object to take Methods have a signature: a name and zero or more arguments Methods declare a data type (primitive or object (or void) they return

Methods Should generally be fairly short Constructors - a "method" to initialize objects Constructors and methods can be over- loaded Constructors and methods can have accessibility modifiers

Constructors Constructors are the mechanism by which new instances of a class are created from the blueprint of the class definition.  The purpose of a constructor is to initialize a new object.  Constructors look something like method definitions except  They always have the same name as the class  They never return any type of value

Constructors You "call" a constructor using the new operator and supplying any needed constructor arguments. Every class has, by default, a constructor: public ClassName() {} that takes no arguments and does no special initialization.

Constructors If you don't define one, Java will create a default, no-arg constructor. If you define any constructor, with or without arguments, Java assumes you know what you are doing and defines no default constructor.

Constructors: Rules of Thumb Remember: the purpose of a constructor is to put a newly created object into a known, initial state. Constructors should not do a lot of processing. Try to separate object initialization from object behavior.

Objects An object is a software bundle of variables and related methods." - Java Tutorial Everything is either a primitive data type or an object Objects are things:  Models of real world, physical things, like Students  Abstract things, like courses, elections, financial transactions

Objects In Java, declaring a variable to hold a primitive data type reserves space for that primitive data type. Declaring a variable to hold an object reserves space to hold a reference to an object of that type (or any derived type).

Objects Declaring a variable to hold an object does not create the object The memory for an object instance is dynamically allocated using the new operator Create object types liberally

Variable (Fields) Local Variables Variables you declare and use only within a method or a smaller block of code. Instance variables In a good object oriented Java class, just about all variables ought to be instance (or local) variables. Each object (instance) will have its own copy of these fields

Variable (Fields) Class variables Qualifying a variable (field) with the keyword static makes that variable a class variable:  There is only one of those variables no matter how many instances of the class are instantiated.  All instances share that class variable

Using Class Variables There are only two good reasons to declare a class variable in Java:  As a static final constant  As a private static internal item of information that is purposely shared among object instances

Problem Specification – CS Student Model enrollment in a CS class: Permit student names to be given on the command line Assign lab partners as student pairs. An odd student will have no partner. List the students in the class (and their lab partner, if any) in reverse order of enrollment.

Classes, Fields, Methods, Objects

Accessibility The creator of a Java class controls what access objects outside the class have to the implementation (the inner details) of objects of her class by giving variables and methods accessibility qualifiers. Unlike in C++, each method or field is given an accessibility modifier.

Accessibility public  All outside objects can call public methods.  Any outside object can potentially change public variables. private  methods are only callable within the instance methods of the class - not by subclasses.  variables are only accessible within the methods of the class - not from subclasses.

Accessibility protected  methods are only callable from the methods of the class and any sub classes.  variables are accessible within the instance methods of the class and any sub classes. "Package access” the default if no other modifier is used:  Instances of any class in the same package may call methods with package access.  Instances of any class in the same package can acess package variables

Encapsulation Information Hiding  objects have public methods that they expose for other objects to use. These methods permit other objects to send "messages" to it. Private variables and methods of the object are implementation details that can be changed at any time without affecting other objects.

Encapsulation Expose Appropriate Methods  Classes should expose to the outside (make public) just the methods needed to make the object do the things it is designed to do;  None of the internal details related to the implementation of the class should be visible to the outside.  supports modularity - an object can be written and maintained independently of other objects.

Composition "An organization of components interacting to achieve a coherent, common behavior" Composition extends the responsibilities of an object by delegating work to additional objects. Composition is the major mechanism for extending the responsibilities of an object. Nearly every object in an object model is composed of, knows of, or works with other objects. ”Java Design" Peter Coad and Mark Mayfield, Prentice Hall, 1996

Composition Create object types liberally The "has-a" relationship

Separation Distinguishing what an object can do versus how it does it Related to the use of Java interface definitions Related to Encapsulation

Generalization Identifying, and possibly organizing, common elements among different entities Hierarchy - inheritance Polymorphism Patterns