I Wish I Knew How To. Begin Object Oriented Programming With Xojo. By Eugene Dakin. July 2015 Edition (1.0)

Similar documents
Chapter 5 Object-Oriented Programming

I Wish I Knew How To. Begin Programming JSON with Xojo. By Eugene Dakin. November 2015 Edition (1.1)

I Wish I Knew How To. Program Plugins With Xojo on Windows. By Eugene Dakin. May 2015 Edition (2.1) For Visual Studio 2013 Community Edition

I Wish I Knew How To. Program Access 2013 with Real Studio Desktop Apps in Windows. By Eugene Dakin. June 2013 Edition (1.7)

CLASSES AND OBJECTS IN JAVA

C++ Inheritance and Encapsulation

Paytm Programming Sample paper: 1) A copy constructor is called. a. when an object is returned by value

Data Structures (list, dictionary, tuples, sets, strings)

ENCAPSULATION. private, public, scope and visibility rules. packages and package level access.

CS304 Object Oriented Programming Final Term

Overview of OOP. Dr. Zhang COSC 1436 Summer, /18/2017

Oops known as object-oriented programming language system is the main feature of C# which further support the major features of oops including:

Intro to OOP Visibility/protection levels and constructors Friend, convert constructor, destructor Operator overloading a<=b a.

Programming II (CS300)

Object oriented programming. Encapsulation. Polymorphism. Inheritance OOP

CS-202 Introduction to Object Oriented Programming

Software Development. Modular Design and Algorithm Analysis

Encapsulation in C++

Object Oriented Programming in Java. Jaanus Pöial, PhD Tallinn, Estonia

XII- COMPUTER SCIENCE VOL-II MODEL TEST I

JAVA MOCK TEST JAVA MOCK TEST II

ENCAPSULATION AND POLYMORPHISM

Chapter 5: Classes and Objects in Depth. Information Hiding

CREATED BY: Muhammad Bilal Arslan Ahmad Shaad. JAVA Chapter No 5. Instructor: Muhammad Naveed

Programming Language Concepts Object-Oriented Programming. Janyl Jumadinova 28 February, 2017

Objects and Classes. 1 Creating Classes and Objects. CSCI-UA 101 Objects and Classes

Subclass Gist Example: Chess Super Keyword Shadowing Overriding Why? L10 - Polymorphism and Abstract Classes The Four Principles of Object Oriented

OOPS Viva Questions. Object is termed as an instance of a class, and it has its own state, behavior and identity.

CPS 506 Comparative Programming Languages. Programming Language

Mobile Application Programming. Swift Classes

Object-Oriented Programming

Principles of Object Oriented Programming. Lecture 4

Programming II (CS300)

CS250 Final Review Questions

Graphical Interface and Application (I3305) Semester: 1 Academic Year: 2017/2018 Dr Antoun Yaacoub

Microsoft Visual Basic 2005: Reloaded

Inheritance and Encapsulation. Amit Gupta

Chapter 12 Object-Oriented Programming. Starting Out with Games & Graphics in C++ Tony Gaddis

Object Oriented Features. Inheritance. Inheritance. CS257 Computer Science I Kevin Sahr, PhD. Lecture 10: Inheritance

What is Inheritance?

Java Object Oriented Design. CSC207 Fall 2014

CmSc 150 Fundamentals of Computing I. Lesson 28: Introduction to Classes and Objects in Java. 1. Classes and Objects

CGS 2405 Advanced Programming with C++ Course Justification

C++ Important Questions with Answers

ITI Introduction to Computing II

Inheritance and Polymorphism

Classes, Objects, and OOP in Java. June 16, 2017

QUESTIONS FOR AVERAGE BLOOMERS

CSCE 156 Computer Science II

I Wish I Knew How To. Program SQLite with Xojo Desktop. By Eugene Dakin. March 2015 Edition (1.2)

OBJECT ORIENTED PROGRAMMING USING C++ CSCI Object Oriented Analysis and Design By Manali Torpe

AP Computer Science Chapter 10 Implementing and Using Classes Study Guide

Chapter 6 Introduction to Defining Classes

MCSA Universal Windows Platform. A Success Guide to Prepare- Programming in C# edusum.com


CMSC 132: Object-Oriented Programming II

Inheritance. OOP components. Another Example. Is a Vs Has a. Virtual Destructor rule. Virtual Functions 4/13/2017

Object Orientated Analysis and Design. Benjamin Kenwright

Get Unique study materials from

Chapter 11. Categories of languages that support OOP: 1. OOP support is added to an existing language

CS304- Object Oriented Programming LATEST SOLVED MCQS FROM FINALTERM PAPERS. MC

Inheritance, and Polymorphism.

G52CPP C++ Programming Lecture 9

(12-1) OOP: Polymorphism in C++ D & D Chapter 12. Instructor - Andrew S. O Fallon CptS 122 (April 3, 2019) Washington State University

Object-Oriented Programming (OOP) Fundamental Principles of OOP

PROGRAMMING LANGUAGE 2

ITI Introduction to Computing II

Programming Exercise 14: Inheritance and Polymorphism

9/21/2010. Based on Chapter 2 in Advanced Programming Using Visual Basic.NET by Bradley and Millspaugh

INHERITANCE & POLYMORPHISM. INTRODUCTION IB DP Computer science Standard Level ICS3U. INTRODUCTION IB DP Computer science Standard Level ICS3U

Lecture 3. COMP1006/1406 (the Java course) Summer M. Jason Hinek Carleton University

PASCAL - OBJECT ORIENTED

CS304 Object Oriented Programming

Java. Classes 3/3/2014. Summary: Chapters 1 to 10. Java (2)

Object oriented programming Concepts

8.1 Inheritance. 8.1 Class Diagram for Words. 8.1 Words.java. 8.1 Book.java 1/24/14

Weiss Chapter 1 terminology (parenthesized numbers are page numbers)

Object Oriented Programming. Solved MCQs - Part 2

CS111: PROGRAMMING LANGUAGE II. Lecture 1: Introduction to classes

CS 6456 OBJCET ORIENTED PROGRAMMING IV SEMESTER/EEE

Polymorphism. Zimmer CSCI 330

More C++ : Vectors, Classes, Inheritance, Templates

Mobile Application Programming. Swift Classes

Glossary. For Introduction to Programming Using Python By Y. Daniel Liang

Programming II (CS300)

Practice for Chapter 11

Compiler Construction Lent Term 2015 Lectures 10, 11 (of 16)

Programming II (CS300)

More C++ : Vectors, Classes, Inheritance, Templates. with content from cplusplus.com, codeguru.com

Lecture 13: Object orientation. Object oriented programming. Introduction. Object oriented programming. OO and ADT:s. Introduction

G Programming Languages - Fall 2012

Object Oriented Programming is a programming method that combines: Advantage of Object Oriented Programming

Encapsulation. Mason Vail Boise State University Computer Science

Introduction to OO Concepts

MaanavaN.Com CS1203 OBJECT ORIENTED PROGRAMMING DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

Elementary Concepts of Object Class


Abstraction in Software Development

Introduction to Programming Microsoft.NET Applications with Visual Studio 2008 (C#)

Developing Microsoft.NET Applications for Windows (Visual Basic.NET)

Transcription:

I Wish I Knew How To Begin Object Oriented Programming With Xojo July Edition (1.0) By Eugene Dakin

Table of Contents Chapter 1 - Introduction to Object Oriented Programming... 6 Being the Architect... 7 Classes... 7 Make an Object... 9 Set and Get Object Data... 10 Dot Operator... 12 Chapter 2 Methods... 14 Simple Method... 14 Method Parameter... 15 Return Method Value... 17 Chapter 3 Constructor and Destructor... 19 Constructor... 19 Constructor Parameters... 21 Constructor Overloading... 22 Destructor... 25 Chapter 4 - Encapsulation... 28 Scope... 28 Encapsulated Property... 28 Chapter 5 Inheritance... 31 Inheritance ClsCar... 32 Base or Parent Class... 36 Chapter 6 Polymorphism... 38 Chapter 7 Introspection... 42 Retrieve Object Properties and Values... 42 Copy Data at Runtime... 46 Chapter 8 Extends and Assigns... 49 Extends... 49 Assigns... 52 Chapter 9 - Boxing and Unboxing... 55 Value Type... 55 Reference Type... 55 Implicit... 56 Explicit... 56 4

Boxing... 56 Unboxing... 56 Implicit Boxing... 57 Explicit Boxing... 57 Implicit Unboxing... 58 Explicit Unboxing... 58 Chapter 10 Setters and Getters... 61 Mutator... 65 Accessor... 65 Immutable... 65 Chapter 11 Overloading and Overriding... 66 Overloading... 66 Overriding... 68 Chapter 12 Delegate... 71 Simple Delegate... 71 Delegate Parameter... 73 Delegate Return Value... 75 Abstract Pointer Delegate... 76 Class Abstract Pointer Delegate... 80 Chapter 13 Class Interface... 82 Index... 88 5

Chapter 4 - Encapsulation Encapsulation is a common word when Object Oriented Programming is used. Encapsulation has all of the objects data hidden within the object and can only be accessed through the methods of the class. Here are some of the many benefits to hiding (making properties Private) which allows the validation of changes to the data, protecting the data from unauthorized access, and allows the data to be consistent. Scope With classes there are three types of scope in Xojo: Public, Protected, and Private. Scope is also called the visibility of the entity (eg. Property, Method, etc.). Scope is very important when working with encapsulation. The general definitions of scope are: a) Public All methods, Windows, and Objects can see and likely access the entity (i.e. Property) within a class. b) Protected The class and any subclasses can access and modify the property/method. c) Private Only the class can access and modify the property/method. None of the properties/methods are given access from outside of the program. Encapsulated Property This example will make a property (Speed) which is invisible to the outside program and is only accessible by calling methods in the Class by setting the property to Private. Figure 14. Example 4-1: Encapsulating a Property Screen Grab The object is made and property is set with a private scope, meaning only a class method can change the property value. Lets show how this program is made. 28

The first step is to create a blank desktop application and drag-and-drop a class Figure 15. Example 4-1: Encapsulated Property Screen Grab Class1 was renamed to ClsCar and a property called Speed was added to the car. When the properties scope was changed to Private, then a red dot appears to the right of the property. Figure 16. Adding a Private Class Property A private property can only be changed by the methods within the class. Two methods with public properties were created that can be accessed outside of the class. Function Constructor() Code 24. Example 4-1: Class Constructor Method 29

//Set PRIVATE Default Class Property value Me.Speed = 15 //Car has zero speed End Function Using our knowledge from the previous chapter, a method called a Constructor is added to the class and is automatically called when a new object from a class is created. Code in the Constructor method sets the speed of the object to 15. Another method is created to update the Window label from the class. Code 25. Example 4-1: Class UpdateLabels Method //Show MyFastCar Settings in Window Window1.LblSpeed.Text = Me.Speed.ToText This is the part of the method where the value in the speed variable is shown on a label in the window. To make all of the methods and property work together, the following code is added to the pushbutton action event. Code 26. Example 4-1: Create Encapsulated Object //Create a Fast Car Dim MyFastCar as New ClsCar //Property values are set with the method MyFastCar.UpdateLabels() When the MyFastCar variable is created from the Class ClsCar, then the Constructor fires and places a default value into the Speed property. The Class UpdateLabels method is then called to show the property value on the label in Window1 which has the value of 15. This example shows how to encapsulate (hide) a property so that only methods in the property can change or be updated by public methods in the class. 30

Index Abstract, 76 Abstract Pointer, 76 Abstract Pointer Delegate, 76 abstraction, 76 Accessor, 65 Assigns, 52 Base Class, 36 Boxing, 56 called, 14 CanRead, 44 CanWrite, 44 Class, 7 Class Interface, 82 Constructor, 19 Constructor Super, 34 coupled, 76 Delegate, 71 Delegate Invoke, 73 Delegate Reference, 72 Delegate Reference Pointer, 72 Dot Operator, 12 entity, 28 Examples 01-01 Create Class Properties, 9 01-02 Create Object, 10 01-03 Set Object Propeties, 11 01-04 Dot Operator, 12 02-01 Using a Method, 14 02-02 Method Parameter, 16 02-03 Return Method Value, 17 03-01 Constructor Method, 20 03-01 Object Constructor, 20 03-02 Constructor Parameter, 21 03-03 Constructor Overload, 23 03-03 Constructor Overloading, 23 03-04 Destructor Method, 26 04-01 Encapsulated Property, 30 05-01 Inherited Class, 35 05-02 Class IsA Comparison, 36 06-01 Polymorphic Method, 39 07-01 Introspection Show Properties, 44 07-02 Introspection Copy Object, 46 08-01 Extends Function, 50 08-02 Assigns Keyword, 52 09-01 Boxing and Unboxing, 59 10-01 Use Computed Get and Set, 63 11-01 Method Overloading, 66 11-02 Method Overriding, 69 12-01 Simple Delegate, 73 12-02 Delegate Parameter, 74 12-03 Delegate Return Value, 76 12-04 Abstract Delegate, 79 12-05 Class Abstract Delegate, 81 13-01 Class Interface, 87 88

Explicit, 56 Explicit Boxing, 57 Explicit Unboxing, 58 Extends, 50 Get, 63 GetProperties, 44 Getter Propery, 61 GetTypeInfo, 44 immutable, 65 Implicit, 56 Implicit Boxing, 57 Implicit Unboxing, 58 Inheritance, 31 Instance, 9 Interface Class, 82 Introspection ArrayInfo, 45 AttributeInfo, 45 AttributeInfoImp, 45 ClassInfo, 45 ConstructorInfo, 45 ConstructorInfoImp, 45 EnumInfo, 45 GenericPrimitiveTypeInfo, 45 GetType, 45 MemberInfo, 45 MethodBase, 45 MethodInfo, 45 MethodInfoImp, 45 ObjectClassInfo, 45 ParameterInfo, 45 ParameterInfoImp, 45 PointerTypeInfo, 45 PropertyInfo, 45 PropertyInfoImp, 45 StructureInfo, 45 TypeInfo, 45 VariantInfo, 45 Invoke Delegate, 73 Invoked, 14 IsA, 36, 37 IsPublic, 44 Me, 15 Member Methods, 12 Member Variables, 12 Method Members, 12 Mutator, 65 NaN, 67 Not a Number, 67 Object, 9 Overloading, 22, 66 Overriding, 68 Parameters, 14 Parent Class, 36 pointer, 76 Private, 28 Property 89

Get, 61 Set, 61 PropertyInfo, 44 Protected, 28 Public, 28 Reference Delegate, 72 Reference Type, 55 Return, 14 Return Type, 14 Scope, 28 Private, 28 Protected, 28 Public, 28 Set, 63 Set Object Property, 10 Setter Property, 61 Super, 31 Super.Constructor, 34 TypeInfo, 44 Unboxing, 56 uncoupling, 76 Value Type, 55 Variable Members, 12 90

The I Wish I Knew series contains technical data and advice that makes sense and contains practical and numerous examples with explanations to allow you to ease into the steep programming curve. You can extend Xojo applications today! This book I Wish I Knew How to Begin Object Oriented Programming with Xojo shows you how to program with object in the three major operating systems. All code has been tested on Xojo r2.2 with Windows 8.1, OS X Yosemite 10.10.4, and Ubuntu 15.04 32-bit versions. The book is written as a guide and reference to Xojo programmers who program Desktop Applications. There are 12 chapters and contains over 90 pages with 29 example programs. Examples include topics such as Polymorphism, Introspection, Extends, Explicit Unboxing, Overriding, and definitions of common terms used in OOP. Many screenshots have been added to show the results of the code with an index to help find topics quickly. This is one of many books at Great White Software. This book can be purchased at http://greatwhite-software.com/rblibrary/ where many great Xojo resources are available. Happy programming! Eugene Eugene Dakin MBA, Ph.D., P.Chem., is an author of Xojo and Real Studio reference materials and has many years of experience in the programming industry. Another great reference book is I Wish I Knew How To Program Win32 Declares for Windows. ISBN: 978-1-927924-12-9 91