James Tam Advanced Composite Types You will learn in this section of notes how to create single and generic instances of non-homogeneous composite types.

Slides:



Advertisements
Similar presentations
James Tam Linked Lists in Pascal Linked Lists In this section of notes you will learn how to create and manage a dynamic list.
Advertisements

Object-Oriented Programming Python. OO Paradigm - Review Three Characteristics of OO Languages –Inheritance It isn’t necessary to build every class from.
Single Variable and a Lot of Variables The declaration int k; float f; reserve one single integer variable called k and one single floating point variable.
Overview of Data Structures and Algorithms
James Tam Arrays In this section of notes you will be introduced to a homogeneous composite type, one- dimensional arrays.
Inheritance Inheritance Reserved word protected Reserved word super
Objectives Introduction to Inheritance and Composition (Subclasses and SuperClasses) Overriding (and extending), and inheriting methods and constructors.
James Tam Records You will learn in this section of notes how to create a new, composite type, that can be composed of different types of elements.
James Tam Arrays In this section of notes you will be introduced to a homogeneous composite type, one- dimensional arrays.
James Tam Arrays In this section of notes you will be introduced to a homogeneous composite type, one- dimensional arrays.
James Tam Arrays In this section of notes you will be introduced to a composite type where all elements must be of the same type (homogeneous): arrays.
James Tam Loops In Python In this section of notes you will learn how to rerun parts of your program without having to duplicate the code.
James Tam Records You will learn in this section of notes how to create a new, composite type, that can be composed of different types of elements.
J. Michael Moore Arrays CSCE 110 From James Tam’s material.
James Tam Records You will learn in this section of notes how to create a new, composite type, that can be composed of different types of elements.
James Tam Getting Started With Pascal Programming What is the basic structure of a Pascal Program Variables in Pascal Performing input and output with.
James Tam Arrays In this section of notes you will be introduced to a homogeneous composite type, one- dimensional arrays.
James Tam Composite Types You will learn in this section of notes how to create single and generic instances of non-homogeneous composite types that are.
James Tam Arrays / Lists In this section of notes you will be introduced to new type of variable that consists of other types.
James Tam Arrays In this section of notes you will be introduced to a homogeneous composite type, one- dimensional arrays.
Class template Describing a generic class Instantiating classes that are type- specific version of this generic class Also are called parameterized types.
J. Michael Moore From James Tam's material Records CSCE 110.
1 Java Object Model Part 2: the Object class. 2 Object class Superclass for all Java classes Any class without explicit extends clause is a direct subclass.
James Tam Records You will learn in this section of notes how to create a new, composite type, that can be composed of different types of elements.
Classes and Objects  A typical Java program creates many objects which interact with one another by sending messages. Through the objects interactions,
PZ04A Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, PZ04A - Scalar and composite data Programming Language.
J. Michael Moore Arrays CSCE 110. J. Michael Moore Typical (although simplified) Problem Write a program that will track student grades in a class. The.
James Tam Classes and Objects You will learn how to define new types of variables.
JAVA 1.5 New Features Dr V. The syntax of the enhanced for loop (for each) for (type variableName : arrayName) { statements } arrayName could be any.
James Tam Lists In this section of notes you will be introduced to new type of variable that consists of other types.
James Tam Advanced Composite Types You will learn in this section of notes how to create single and generic instances of non-homogeneous composite types.
State,identity and behavior of objects Sem III K.I.R.A.S.
Object Oriented Software Development
CPSC 231: Classes and Objects You will learn how to define new types of variables that can have custom attributes and capabilities slide 1.
The Data Element. 2 Data type: A description of the set of values and the basic set of operations that can be applied to values of the type. Strong typing:
Chapter 5 - Writing a Problem Domain Class Definition1 Chapter 5 Writing a Problem Domain Class Definition.
Java Class Syntax CSIS 3701: Advanced Object Oriented Programming.
CSC 212 Object-Oriented Programming and Java Part 1.
Method Overriding Remember inheritance: when a child class inherits methods, variables, etc from a parent class. Example: public class Dictionary extends.
File Processing - Introduction MVNC1 File Processing BASIC CONCEPTS & TERMINOLOGY.
James Tam Classes and Objects You will learn how to define new types of variables.
Object Based Programming Chapter 8. 2 In This Chapter We will learn about classes Garbage Collection Data Abstraction and encapsulation.
Topic 1 Object Oriented Programming. 1-2 Objectives To review the concepts and terminology of object-oriented programming To discuss some features of.
Sheet 1 DocEng’03, Grenoble, November 2003 Model Driven Architecture based XML Processing Ivan Kurtev, Klaas van den Berg University of Twente, the Netherlands.
CIS 270—Application Development II Chapter 18-Generics.
Object Oriented Analysis: Associations. 2 Object Oriented Modeling BUAD/American University Class Relationships u Classes have relationships between each.
8-1 Compilers Compiler A program that translates a high-level language program into machine code High-level languages provide a richer set of instructions.
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Programming Logic & Design Second Edition by Tony Gaddis.
1 MATERI PENDUKUNG TIPE DATA Matakuliah: M0074/PROGRAMMING II Tahun: 2005 Versi: 1/0.
CPS120: Introduction to Computer Science Lecture 16 Data Structures, OOP & Advanced Strings.
Topic 1 Object Oriented Programming. 1-2 Objectives To review the concepts and terminology of object-oriented programming To discuss some features of.
 Variables are nothing but reserved memory locations to store values. This means that when you create a variable you reserve some space in memory. 
M1G Introduction to Programming 2 2. Creating Classes: Game and Player.
1 Scalar and composite data Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
Scalar and composite data Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
Object Based Programming Chapter 8. 2 Contrast ____________________ Languages –Action oriented –Concentrate on writing ________________ –Data supports.
Phil Tayco Slide version 1.0 Created Sep 10, 2017
Objects as a programming concept
CPSC 231: Classes and Objects
Chapter 16 UML Class Diagrams.
Objects as a programming concept
CPSC 231: Classes and Objects
Object-oriented programming
Object Based Programming
GCSE Computing Databases.
CS2011 Introduction to Programming I Objects and Classes
ICT Programming Lesson 4:
Arrays In this section of notes you will be introduced to a homogeneous composite type, one-dimensional arrays One-dimensional arrays in Pascal.
Arrays In this section of notes you will be introduced to a composite type where all elements must be of the same type (homogeneous): arrays Homogeneous.
Understanding Variables
Presentation transcript:

James Tam Advanced Composite Types You will learn in this section of notes how to create single and generic instances of non-homogeneous composite types.

James Tam What You Know How to create composite types (that are composed of other types e.g., integers, real numbers, strings) which are homogeneous.  Python implementation of this composite type: List  Typical implementation of this composite type in other programming languages (e.g., ‘C’, “C++”, “Pascal”, “Java”): Array

James Tam What You Will Learn How to create composite types that aren’t strictly homogeneous (elements are all the same).

James Tam The List Revisited This type of list that you have seen before is referred to as an array:  Each element stores the same type of information.  (Usually) the size of each element is the same.  Examples: —percentages = [0.0, 0.0, 0.0, 0.0, 0.0] —letters = [‘A’, ‘A’, ‘A’] —names = [“James Tam”, “Stacey Walls”, “Jamie Smyth”]

James Tam The List Revisited (2) Problem: What if different types of information needs to be tracked as a composite type? Example, storing information about a client: First name Last name Phone number Address Postal code address Total purchases made …series of characters …numerical or character …series of characters …numerical or character

James Tam The List Revisited (3) The array type employed by other programming languages won’t work (each element must store the same type of information) The list implementation used in Python provides more features that a typical array. If just a few clients need to be tracked then a list can be employed: firstClient = ["James", "Tam", "(403) ", "ICT 707, 2500 University Dr NW", "T2N-1N4", 0]

James Tam The List Revisited (4) (Or as a small example) def display (firstClient): print "DISPLAYING CLIENT INFORMATION" print " " for i in range (0, 6, 1): print firstClient [i] # MAIN firstClient = ["James", "Tam", "(403) ", "ICT 707, 2500 University Dr NW", "T2N-1N4", 0] display (firstClient)

James Tam The List Revisited (5) If only a few instances of the composite type (e.g., “Clients”) need to be created then a list can be employed. firstClient = ["James", "Tam", "(403) ", "ICT 707, 2500 University Dr NW", "T2N-1N4", 0] secondClient = ["Peter", "Griffin", "(708) ", "725 Spoon Street", "NA", 100]

James Tam Classes Can be used define a generic template for a new non- homogeneous composite type. This template defines what an instance or example of this new composite type would consist of but it doesn’t create an instance.

James Tam Defining A Class Format: class : name of first field = name of second field = Example: class Client: firstName = "default" lastName = "default" phone = "(123) " address = "default address" postalCode = "XXX-XXX" = purchases = 0 Describes what information that would be tracked by a “Client” but doesn’t actually create a client in memory

James Tam Creating An Instance Of A Class Format: = () Example: firstClient = Client ()

James Tam Defining A Class Vs. Creating An Instance Of That Class Defining a class  A template that describes that class: how many fields, what type of information will be stored by each field, what default information will be stored in a field. Creating a class  Examples of (instantiations) of that class which can take on different forms.

James Tam Accessing And Changing The Fields Format:. Example: The full version can be found in UNIX under /home/courses/217/examples/composites/client.py firstClient = Client () firstClient.firstName = "James" firstClient.lastName = "Tam" firstClient. = print firstClient.firstName print firstClient.lastName print firstClient.phone print firstClient.address print firstClient.postalCode print firstClient. print firstClient.purchases

James Tam What Is The Benefit Of Defining A Class It allows new types of variables to be declared. The new type can model information about most any arbitrary entity:  Car  Movie  Your pet  A biological entity in a simulation  A ‘critter’ a video game  An ‘object’ in a video game  Etc.

James Tam What Is The Benefit Of Defining A Class (2) Unlike creating a composite type by using a list a predetermined number of fields can be specified and those fields can be named. class Client: firstName = "default" lastName = "default" phone = "(123) " address = "default address" postalCode = "XXX-XXX" = purchases = 0 firstClient = Client () print firstClient.middleName

James Tam What Is The Benefit Of Defining A Class (2) Unlike creating a composite type by using a list a predetermined number of fields can be specified and those fields can be named. class Client: firstName = "default" lastName = "default" phone = "(123) " address = "default address" postalCode = "XXX-XXX" = purchases = 0 firstClient = Client () print firstClient.middleName There is no field by this name

James Tam You Should Now Know How a list can be used to store different types of information (non-homogeneous composite type) How to define an arbitrary composite type using a class What are the benefits of defining a composite type by using a class definition over using a list How to create instances of a class (instantiate) How to access and change the attributes or fields of a class