YG - CS1701. 2 3 4 5 6 7 8 Concept of Encapsulation What is encapsulation? - data and functions/methods are packaged together in the class normally.

Slides:



Advertisements
Similar presentations
Final and Abstract Classes
Advertisements

Chapter 4&5 Defining Classes Copyright © 2010 Pearson Addison-Wesley. All rights reserved.
Applying OO Concepts Using Java. In this class, we will cover: Defining classes Defining methods Defining variables Encapsulation Class methods and variables.
CS 211 Inheritance AAA.
Road Map Introduction to object oriented programming. Classes
OOP in Java Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
CS 106 Introduction to Computer Science I 03 / 21 / 2008 Instructor: Michael Eckmann.
Evan Korth New York University Computer Science I Classes and Objects Professor: Evan Korth New York University.
Evan Korth New York University Computer Science I Classes and Objects Professor: Evan Korth New York University.
Terms and Rules Professor Evan Korth New York University (All rights reserved)
Applying OO Concepts Using Java. In this class, we will cover: Overriding a method Overloading a method Constructors Mutator and accessor methods The.
OOP in Java Fawzi Emad Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Inheritance using Java
Programming Languages and Paradigms Object-Oriented Programming.
CSM-Java Programming-I Spring,2005 Objects and Classes Overview Lesson - 1.
Introduction to Object Oriented Programming. Object Oriented Programming Technique used to develop programs revolving around the real world entities In.
BPJ444: Business Programming Using Java Classes and Objects Tim McKenna
COP INTERMEDIATE JAVA Designing Classes. Class Template or blueprint for creating objects. Their definition includes the list of properties (fields)
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.
Chapter 7 Objects and Classes 1 Fall 2012 CS2302: Programming Principles.
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.
Classes In C++ 1. What is a class Can make a new type in C++ by declaring a class. A class is an expanded concept of a data structure: instead of holding.
 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.
CSC241 Object-Oriented Programming (OOP) Lecture No. 4.
Programming in Java CSCI-2220 Object Oriented Programming.
Summing Up Object Oriented Design. Four Major Components: Abstraction modeling real-life entities by essential information only Encapsulation clustering.
1 Chapter Four Creating and Using Classes. 2 Objectives Learn about class concepts How to create a class from which objects can be instantiated Learn.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 26 - Java Object-Based Programming Outline 26.1Introduction.
COP INTERMEDIATE JAVA Designing Classes. Class Template or blueprint for creating objects. Their definition includes the list of properties (fields)
Classes. Constructor A constructor is a special method whose purpose is to construct and initialize objects. Constructor name must be the same as the.
Chapter 4&5 Defining Classes Copyright © 2010 Pearson Addison-Wesley. All rights reserved.
08 Encapsulation and Abstraction. 2 Contents Defining Abstraction Levels of Abstraction Class as Abstraction Defining a Java Class Instantiating a Class.
CS170 ygao JAVA, C4Slide 1. CS170 ygao JAVA, C4Slide 2.
OOP in C++ CS 124. Program Structure C++ Program: collection of files Source (.cpp) files be compiled separately to be linked into an executable Files.
Chapter 3 Introduction to Classes and Objects Definitions Examples.
Object-Oriented Programming (OOP) What we did was: (Procedural Programming) a logical procedure that takes input data, processes it, and produces output.
More about Java Classes Writing your own Java Classes More about constructors and creating objects.
Classes, Interfaces and Packages
Basic Concepts of OOP.  Object-Oriented Programming (OOP) is a type of programming added to php5 that makes building complex, modular and reusable web.
Presented by Ted Higgins, SQL Server DBA An Introduction to Object – Oriented Programming.
Java Programming, Second Edition Chapter Three Using Methods, Classes, and Objects.
In this class, we will cover: Overriding a method Overloading a method Constructors Mutator and accessor methods The import statement and using prewritten.
Chapter 4: More Object Concepts. Objectives Understand blocks and scope Overload a method Avoid ambiguity Create and call constructors with parameters.
Topics Instance variables, set and get methods Encapsulation
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.
Reference Types CSE301 University of Sunderland Harry R Erwin, PhD.
Internet Computing Module II. Syllabus Creating & Using classes in Java – Methods and Classes – Inheritance – Super Class – Method Overriding – Packages.
C++ General Characteristics: - Mixed typing system - Constructors and destructors - Elaborate access controls to class entities.
Defining Data Types in C++ Part 2: classes. Quick review of OOP Object: combination of: –data structures (describe object attributes) –functions (describe.
Classes CS 162 (Summer 2009). Parts of a Class Instance Fields Methods.
Object Based Programming Chapter 8. 2 Contrast ____________________ Languages –Action oriented –Concentrate on writing ________________ –Data supports.
Computer Programming II Lecture 5. Introduction to Object Oriented Programming (OOP) - There are two common programming methods : procedural programming.
Object-Oriented Programming Using C++ Third Edition Chapter 7 Using Classes.
OOP: Encapsulation &Abstraction
Final and Abstract Classes
More About Objects and Methods
Chapter 3: Using Methods, Classes, and Objects
Object-Oriented Programming Using C++
HIGHLEVEL REVIEW Chapter 9 Objects and Classes
Object Based Programming
Classes & Objects: Examples
Learning Objectives Classes Constructors Principles of OOP
Week 3 Object-based Programming: Classes and Objects
Java – Inheritance.
Applying OO Concepts Using Java
Static is one of the modifiers that determine variable and method characteristics. The static modifier associates a variable or method with its class.
Applying OO Concepts Using Java
Final and Abstract Classes
SPL – PS3 C++ Classes.
Presentation transcript:

YG - CS1701

2

3

4

5

6

7

8 Concept of Encapsulation What is encapsulation? - data and functions/methods are packaged together in the class normally with the same scope of the accessibility in the memory Why encapsulation - Objects no longer need to be dependent upon any “outside” functions and data after the creation - Provide ADT (Abstract Data Types) - Easier in coding - Promote standards in OOP

YG - CS1709

10

YG - CS17011

YG - CS17012

YG - CS17013 Classes vs. Objects Class is a data structure that encapsulates data and functions. Data in a class are called member data, class variables, instance variables, or fields. Functions in a class are called member functions or methods. Constructors are special methods. Objects are the instance of a class. Creation of the objects and instantiation of the objects are all referring to memory allocation to hold the data and methods of the objects. In Java, all objects are created dynamically using new operator. For example: ClassName ObjName = new ClassName();

YG - CS17014

YG - CS17015

YG - CS17016

YG - CS17017

YG - CS17018

YG - CS17019

YG - CS17020

YG - CS17021

YG - CS17022

YG - CS17023 Characteristics of Constructors A special method that has the same name of the class without return type, not even void. Constructor will be automatically called whenever an object is created. Like a method, constructor can be overloaded for the flexibility of the object creation. A super class constructor can be called by a sub class object as: super();

YG - CS17024

YG - CS17025

YG - CS17026 In OOP, particularly in Java, get() means to return one of object’s member data get() usually has a return type and takes no argument Use meaningful name for a get() method get methods

YG - CS17027 In OOP, particularly in Java, set() means to set object’s member data set() usually has void return and takes argument(s) to set the member data set() also checks the validity of the data before it sets Use meaningful name for a set() method set methods

YG - CS17028

YG - CS17029

YG - CS17030

YG - CS17031

YG - CS17032

YG - CS17033

YG - CS17034

YG - CS17035

YG - CS17036

YG - CS17037

YG - CS17038

YG - CS17039

YG - CS17040

YG - CS17041

YG - CS17042

YG - CS17043

YG - CS17044

YG - CS17045

YG - CS17046

YG - CS17047

YG - CS17048

YG - CS17049

YG - CS17050

YG - CS17051 Static Fields What is a static field?  a variable that is not associated with any instance of the class, therefore it’s a class-wide field/variable/data  a variable that can be used without creation of the object  a private static field can be only use within the current class  can be constant (final), so it’s value cannot be modified; must be initialized when declaring Why static fields?  keep tracking class-wide information  Convenient to use and save memory  Be careful data encapsulation in using static fields

YG - CS17052

YG - CS17053

YG - CS17054

YG - CS17055

YG - CS17056

YG - CS17057

YG - CS17058

YG - CS17059

YG - CS17060

YG - CS17061

YG - CS17062

YG - CS17063

YG - CS17064

YG - CS17065

YG - CS17066

YG - CS17067

YG - CS17068

YG - CS17069

YG - CS17070

YG - CS17071

YG - CS17072

YG - CS17073

YG - CS17074

YG - CS17075

YG - CS17076