Creating Your OwnClasses

Slides:



Advertisements
Similar presentations
The Line Class Suppose you are involved in the development of a large mathematical application, and this application needs an object to represent a Line.
Advertisements

Written by: Dr. JJ Shepherd
1 Classes, Encapsulation, Methods and Constructors (Continued) Class definitions Instance data Encapsulation and Java modifiers Method declaration and.
Road Map Introduction to object oriented programming. Classes
C# Programming: From Problem Analysis to Program Design1 Creating Your Own Classes C# Programming: From Problem Analysis to Program Design 3rd Edition.
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)
Understanding class definitions Looking inside classes.
Classes in C++ Bryce Boe 2012/08/15 CS32, Summer 2012 B.
More C++ Bryce Boe 2013/07/18 CS24, Summer 2013 C.
Classes and Class Members Chapter 3. 3 Public Interface Contract between class and its clients to fulfill certain responsibilities The client is an object.
Writing Classes (Chapter 4)
Chapter 5 - Writing a Problem Domain Class Definition1 Chapter 5 Writing a Problem Domain Class Definition.
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.
Tuc Goodwin  Object and Component-Oriented Programming  Classes in C#  Scope and Accessibility  Methods and Properties  Nested.
More about Class 靜宜大學資工系 蔡奇偉副教授 ©2011. 大綱 Instance Class Members Class members can be associated with an instance of the class or with the class as a.
Java Objects and Classes. Overview n Creating objects that belong to the classes in the standard Java library n Creating your own classes.
Chapter 4 -2 part Writing Classes 5 TH EDITION Lewis & Loftus java Software Solutions Foundations of Program Design © 2007 Pearson Addison-Wesley. All.
10-Nov-15 Java Object Oriented Programming What is it?
JAVA Classes Review. Definitions Class – a description of the attributes and behavior of a set of computational objects Constructor – a method that is.
Chapter 10 Defining Classes. The Internal Structure of Classes and Objects Object – collection of data and operations, in which the data can be accessed.
Overview The Basics – Python classes and objects Procedural vs OO Programming Entity modelling Operations / methods Program flow OOP Concepts and user-defined.
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.
Class Fundamentals BCIS 3680 Enterprise Programming.
Structure A Data structure is a collection of variable which can be same or different types. You can refer to a structure as a single variable, and to.
Chapter 11 An introduction to object-oriented design.
Comp1004: Building Better Objects II Encapsulation and Constructors.
C# Programming: From Problem Analysis to Program Design1 Creating Your Own Classes C# Programming: From Problem Analysis to Program Design 4th Edition.
Classes CS 162 (Summer 2009). Parts of a Class Instance Fields Methods.
Object Oriented Programming. Constructors  Constructors are like special methods that are called implicitly as soon as an object is instantiated (i.e.
Copyright © 2012 Pearson Education, Inc. Chapter 4 Writing Classes : Review Java Software Solutions Foundations of Program Design Seventh Edition John.
Object-Oriented Programming (part 1 – Data Encapsulation)
Creating Your Own Classes
Classes (Part 1) Lecture 3
Object-Oriented Programming: Classes and Objects
Understand the Fundamentals of Classes
Inheritance and Polymorphism
Intro To Classes Review
Microsoft Visual Basic 2005: Reloaded Second Edition
Inheritance AKEEL AHMED.
Road Map Introduction to object oriented programming. Classes
Methods The real power of an object-oriented programming language takes place when you start to manipulate objects. A method defines an action that allows.
Classes In C#.
Understanding class definitions
METHODS AND BEHAVIORS AKEEL AHMED.
Chapter 5 – Writing Classes
Ch 4: Writing Classes Java Software Solutions Foundations of Program Design Sixth Edition by Lewis & Loftus Coming up: Classes and Objects.
Chapter 4: Writing classes
Object-oriented Design in Processing
IFS410: Advanced Analysis and Design
Classes & Objects: Examples
String Methods: length substring
Encapsulation and Constructors
Outline Writing Classes Copyright © 2012 Pearson Education, Inc.
Classes, Encapsulation, Methods and Constructors (Continued)
Object-oriented Design in Processing
Class Everything if Java is in a class. The class has a constructor that creates the object. public class ClassName private Field data (instance variables)
Basics of OOP A class is the blueprint of an object.
Understanding class definitions
Outline Anatomy of a Class Encapsulation Anatomy of a Method
CIS16 Application Development and Programming using Visual Basic.net
CIS 199 Final Review.
Object-oriented Design in Processing
Dr. R Z Khan Handout-3 Classes
Classes and Objects CGS3416 Spring 2019.
Object-oriented Design in Processing
ITE “A” GROUP 2 ENCAPSULATION.
Creating and Using Classes
CSG2H3 Object Oriented Programming
Presentation transcript:

Creating Your OwnClasses AKEEL AHMED

Overview The Object Concept Private Member Data Constructor Instance Methods, Accessor, Mutators, Property Named and Optional Parameters

The Object Concept To use an object-oriented approach, the solution is defined in terms of a collection of cooperating objects. Each of the objects is capable of sending messages to other objects and receiving messages from objects. Each object is also capable of processing data.. An object is one instance or example of a class. When you define the class, you describe its attributes, or characteristics or fields, in terms of data and its behaviors, or methods, in terms of what kinds of things it can do.

Private Member Data When you define a class and determine what data members it should have, you declare instance variables or fields that represent the state of an object.. These fields are declared inside the class, not inside any specific method They become visible to all members of the class, including all of the method members. Create Class with member data in visual Studio. class Student{ private int id; private String name; }

Constructor Constructors are special types of methods used to create objects . Constructors differ from other methods. Constructors do not return a value, but the keyword void is not included.You receive an error message if you type void as part of the constructor method heading. Constructors use the same identifier (name) as the class name. Constructors are methods. Like other methods, they can be overloaded //Default constructor public Student ( ) { } //Constructor with one parameter public Student (string sID ){ studentNumber = sID; }

Writing Your Own Instance Methods When you define the methods of the class, you are writing instance methods. Instance methods do not use the static keyword in their heading To call an instance method, however, an object must be instantiated and associated with the method. class Motorcycle { public void StartEngine() { Console.WriteLine(”Instance method”); } } Motorcycle motor=new Motorcycle(); motor.StartEngine();

Accessor To read the current state or value of an object member’s data, accessors can be used. Accessors are also referred to as getters.

Mutators To change the current state or value of an object member’s data, special methods called mutators can be used. Mutators are sometimes called setters.

Property One of the underlying themes of object-oriented programming is encapsulation, which states that the internal representation of an object is generally hidden, thus member data are defined with private access. A property looks like a data field, but it does not directly represent a storage location. Properties are more closely aligned to methods. They provide a way to change or retrieve private member data.

Property

Conditional Expressions A conditional expression is also referred to as a test condition. Shorter and more concise when dealing with direct value comparisons and assignments. int x = 10; int y = 20; int maxValue = (x > y) ? x : y; int minValue = (x < y) ? x : y;

Decision Statements(If-else) A one-way selection statement is used when an expression needs to be tested. When the result of the expression is true, additional processing is performed.

Switch Selection Statement The switch statement is considered a multiple selection structure. It also goes by the name case statement The switch or case statement allows you to perform a large number of alternatives based on the value of a single variable