This document discusses polymorphism and object-oriented programming concepts. It provides examples of polymorphism in a veterinary clinic simulation. A class hierarchy is defined for different types of pets. Procedures are defined to process a collection of pets polymorphically by calling methods like Eat() without knowing the specific pet type. This allows managing various pet types uniformly through a single collection rather than separate collections for each type.
Utah Code Camp 2014 - Learning from Data by Thomas HollowayThomas Holloway
The document provides an overview of machine learning and artificial intelligence goals including deduction, reasoning, problem solving, knowledge representation, planning, learning, natural language processing, motion and manipulation, perception, social intelligence and creativity. It discusses different machine learning techniques like supervised learning, unsupervised learning, reinforcement learning and developmental learning. It also covers topics like linear regression, logistic regression, neural networks, overfitting, regularization and more.
1. The document discusses polymorphism and interfaces in object-oriented programming. It covers inheritance, abstract classes, abstract methods, and interfaces.
2. Abstract classes can have both abstract and non-abstract methods, and prevent direct instantiation. Concrete subclasses must implement all abstract methods.
3. Interfaces provide a way for classes to take on common roles or behaviors without multiple inheritance. Classes implement interfaces to take on those roles.
This lecture covers data structures and iteration. It discusses arrays as ordered collections of values that allow items to be accessed by index. Python offers two array-like data structures: lists, which are mutable, and tuples, which are immutable. Loops allow code to repeatedly execute and come in two main types - while loops, which repeat while a condition is true, and for loops. Break and continue statements can be used in loops to exit or skip iterations under certain conditions.
Here are three classes that meet the requirements outlined in the homework:
1. Employee class with get/set methods for name, salary, and method to calculate yearly salary with a raise.
2. Invoice class with get/set methods for part number, description, quantity, price, and method to calculate invoice amount.
3. Date class with get/set methods for month, day, year, and method to display date in MM/DD/YYYY format.
Programming Fundamentals Lecture 3 covered data structures and iteration. Data structures allow storing multiple pieces of data in an organized way. Arrays are ordered collections of values that can be accessed by index. Python offers lists and tuples, where lists are mutable and tuples are immutable. Loops called iteration allow repeatedly running a block of code. While loops repeat while a condition is true. Break and continue can be used in loops to exit early or skip iterations conditionally.
How I Learned to Stop Worrying and Love Legacy Code - Ox:Agile 2018Mike Harris
I never wrote it; everybody else did! How many times have you waded through an ageing, decaying, tangled forrest of code and wished it would just die? How many times have you heard someone say that what really needs to happen is a complete rewrite? I have heard this many times, and, have uttered that fatal sentence myself. But shouldn’t we love our legacy code? Doesn’t it represent our investment and the hard work of ourselves and our predecessors? Throwing it away is dangerous, because, before we do, we’ll need to work out exactly what it does, and we’ll need to tweeze out that critical business logic nestled in a deeply entangled knot of IF statements. It could take us years to do, and we’ll have to maintain two systems whilst we do it, inevitably adding new features to them both. Yes we get to reimplement using the latest, coolest programming language, instead of an old behemoth, but how long will our new cool language be around, and who will maintain that code, when it itself inevitably turns to legacy? We can throw our arms in the air, complaining and grumbling about how we didn’t write the code, how we would never have written it the way it is, how those that wrote it were lesser programmers, possibly lesser humans themselves, but the code still remains, staring us in the face and hanging around for longer that we could possibly imagine. We can sort it out, we can improve it, we can make it testable, and we can learn to love our legacy code.
https://www.youtube.com/watch?v=qRP45l5UugE
Utah Code Camp 2014 - Learning from Data by Thomas HollowayThomas Holloway
The document provides an overview of machine learning and artificial intelligence goals including deduction, reasoning, problem solving, knowledge representation, planning, learning, natural language processing, motion and manipulation, perception, social intelligence and creativity. It discusses different machine learning techniques like supervised learning, unsupervised learning, reinforcement learning and developmental learning. It also covers topics like linear regression, logistic regression, neural networks, overfitting, regularization and more.
1. The document discusses polymorphism and interfaces in object-oriented programming. It covers inheritance, abstract classes, abstract methods, and interfaces.
2. Abstract classes can have both abstract and non-abstract methods, and prevent direct instantiation. Concrete subclasses must implement all abstract methods.
3. Interfaces provide a way for classes to take on common roles or behaviors without multiple inheritance. Classes implement interfaces to take on those roles.
This lecture covers data structures and iteration. It discusses arrays as ordered collections of values that allow items to be accessed by index. Python offers two array-like data structures: lists, which are mutable, and tuples, which are immutable. Loops allow code to repeatedly execute and come in two main types - while loops, which repeat while a condition is true, and for loops. Break and continue statements can be used in loops to exit or skip iterations under certain conditions.
Here are three classes that meet the requirements outlined in the homework:
1. Employee class with get/set methods for name, salary, and method to calculate yearly salary with a raise.
2. Invoice class with get/set methods for part number, description, quantity, price, and method to calculate invoice amount.
3. Date class with get/set methods for month, day, year, and method to display date in MM/DD/YYYY format.
Programming Fundamentals Lecture 3 covered data structures and iteration. Data structures allow storing multiple pieces of data in an organized way. Arrays are ordered collections of values that can be accessed by index. Python offers lists and tuples, where lists are mutable and tuples are immutable. Loops called iteration allow repeatedly running a block of code. While loops repeat while a condition is true. Break and continue can be used in loops to exit early or skip iterations conditionally.
How I Learned to Stop Worrying and Love Legacy Code - Ox:Agile 2018Mike Harris
I never wrote it; everybody else did! How many times have you waded through an ageing, decaying, tangled forrest of code and wished it would just die? How many times have you heard someone say that what really needs to happen is a complete rewrite? I have heard this many times, and, have uttered that fatal sentence myself. But shouldn’t we love our legacy code? Doesn’t it represent our investment and the hard work of ourselves and our predecessors? Throwing it away is dangerous, because, before we do, we’ll need to work out exactly what it does, and we’ll need to tweeze out that critical business logic nestled in a deeply entangled knot of IF statements. It could take us years to do, and we’ll have to maintain two systems whilst we do it, inevitably adding new features to them both. Yes we get to reimplement using the latest, coolest programming language, instead of an old behemoth, but how long will our new cool language be around, and who will maintain that code, when it itself inevitably turns to legacy? We can throw our arms in the air, complaining and grumbling about how we didn’t write the code, how we would never have written it the way it is, how those that wrote it were lesser programmers, possibly lesser humans themselves, but the code still remains, staring us in the face and hanging around for longer that we could possibly imagine. We can sort it out, we can improve it, we can make it testable, and we can learn to love our legacy code.
https://www.youtube.com/watch?v=qRP45l5UugE
• Is more intelligent than human ???
– Of course Not!
• A slave that only does what it is told
• Is always right; can never be wrong
• Good at performing lengthy and recurring tasks
The slides for a lecture about the Ruby programming language. This language was given at FEUP, on a course called "Laboratories of Object-Oriented Programming".
This document discusses using inheritance versus interfaces to model cat behavior in an object-oriented simulation. It describes how inheritance leads to maintenance issues when requirements change. The document proposes using interfaces to separate behaviors that may vary (eating, purring) from the cat class. This allows different concrete behavior classes to be composed into cat objects at runtime. The strategy pattern is applied to make behaviors pluggable and avoid tight coupling between behaviors and cats. Overall this improves flexibility, maintainability and reuse when requirements change.
[YIDLUG] Programming Languages Differences, The Underlying Implementation 1 of 2Yo Halb
Algebra allows representing mathematical relationships with variables in a standardized way. It provides benefits like readability through use of variables and easier calculation by setting up equations to solve for unknown values. Boolean algebra applies the same concepts to true/false values where true is represented by 1 and false by 0. Computer programming languages leverage algebraic concepts with functions, variables, equations, and Boolean logic to solve problems.
The Functional Programmer's Toolkit (NDC London 2019)Scott Wlaschin
(slides and video at https://fsharpforfunandprofit.com/fptoolkit)
The functional programming community has a number of patterns with strange names such as monads, monoids, functors, and catamorphisms.
In this beginner-friendly talk, we'll demystify these techniques and see how they all fit together into a small but versatile "tool kit".
We'll then see how the tools in this tool kit can be applied to a wide variety of programming problems, such as handling missing data, working with lists, and implementing the functional equivalent of dependency injection.
Learn Polymorphism in Python with Examples.pdfDatacademy.ai
In Python, polymorphisms refer to the occurrence of something in multiple forms. As part of polymorphism, a Python child class has methods with the same name as a parent class method. This is an essential part of programming. A single type of entity is used to represent a variety of types in different contexts (methods, operators, objects, etc.)
visit by :-https://www.datacademy.ai/learn-polymorphism-python-examples/
This document provides an overview of object-oriented programming concepts including classes, objects, inheritance, abstraction, encapsulation, and polymorphism. It defines OOP as an engineering approach for building software systems based on modeling real-world entities as classes and objects that exchange messages. Key concepts are explained such as classes defining attributes and behaviors of objects, objects being instances of classes, and communication between objects occurring through messages. The four main principles of OOP - inheritance, abstraction, encapsulation, and polymorphism - are also summarized.
This document provides an overview of the lessons and content covered in Module 3 of an online coding curriculum. It outlines four lessons on variables, strings, and networks/the internet. The lessons introduce key concepts like variables, data types, strings, methods, and network protocols. They include warm-up activities, gameplay in the coding game Ozaria to reinforce concepts, and extension activities. The document provides guidance for teachers on preparing for and teaching the lessons, which combine presentation of concepts with hands-on practice and checkpoints for student understanding.
Python Homework Help has the best homework help experts for your academic homework. Our Python experts hold Ph.D. degrees and can help you in preparing accurate solutions and answers for your Python homework questions. Our panel of online Python experts will help you get your basics right in order to understand and tackle difficult problems.
Reach out to our team via: -
Website: - https://www.pythonhomeworkhelp.com/
Email: support@pythonhomeworkhelp.com
Call/WhatsApp: +1(315)557–6473
We provide the best Python Homework Help online, and we guarantee that the clients get the highest score. We can work in a short time duration by maintaining the quality of work. Your deadline becomes our priority when you hire us!
Reach out to our team via: -
Website: - https://www.pythonhomeworkhelp.com/
Email: support@pythonhomeworkhelp.com
Call/WhatsApp: +1(315)557–6473
From the 2017 HPCC Systems Community Day:
Roger Dev gives an update on the new algorithms and other innovative features in our machine learning library.
Roger Dev
Senior Architect, LexisNexis Risk Solutions
Roger is a Senior Architect working with John Holt on the Machine Learning Team. He recently joined HPCC Systems from CA Technologies. Roger has been involved in the implementation and utilization of machine learning and AI techniques for many years, and has over 20 patents in diverse areas of software technology.
Build a virtual pet with javascript (april 2017)Thinkful
This document provides an overview of building a virtual pet game using JavaScript. It introduces JavaScript concepts like variables, objects, functions, and conditional statements. It outlines the goals of building a functional pet game to practice programming skills and covers specific coding challenges like adding properties to a pet object and writing functions to feed and exercise the pet. The document also provides context on JavaScript and programming in general.
LESSON 3A. INTRODUCTION TO ITERATION: LOOPS, TRACE TABLES, WHILE LOOPS
Introduction to Iteration and loops. The theory behind loops and how they work. Create and adapt programs using loops. Intro to the random number generator. Learn about trace tabling (white box testing). Example of a trace table and dry run. Wonders of the Fibonacci sequence. Examples of Iteration in game design. Focus on While loops. Challenges, tasks (with solutions), suggested videos, big ideas discussion and research and HW included. Introducing Ada Lovelace and Charles Babbage.
The document discusses principles and best practices for writing high-quality code, including keeping code simple, avoiding duplication, using object-oriented design principles like SOLID, giving variables and methods meaningful names, properly structuring classes, methods and variables, and applying principles of encapsulation and inheritance. It emphasizes that code quality is important to reduce development costs and improve productivity.
Java is an object-oriented programming language and platform. It uses a virtual machine (JVM) to run bytecode, making Java programs platform independent. The JVM handles memory management through garbage collection. Java uses classes and objects to implement OOP concepts. Variables are declared with a specific primitive data type or class type. Java supports control flow statements like if/else and loops. Arrays allow storing multiple values of the same type. Methods define reusable blocks of code that can operate on objects.
This document provides an introduction to object-oriented programming (OOP) concepts. It discusses procedural programming and its limitations. OOP aims to overcome these limitations through concepts like encapsulation, inheritance, polymorphism, and abstraction. Encapsulation binds data and functions together in classes. Inheritance allows deriving new classes from existing classes. Polymorphism allows the same action to be performed in different ways. Abstraction describes things at a conceptual level. Examples are provided to illustrate these core OOP concepts. The next lecture will cover implementing OOP in C# and building a game with Unity 3D.
SI is supplemental instruction led by Caleb Peacock to help develop study skills. Variables are used to store and reference values in code. There are different data types like integers, floats, and strings. Variables must start with a letter or underscore and can include numbers and underscores but no spaces. Constant variables store fixed values in all caps. Comments describe code and are preceded by #. Basic math operations and mixing data types were demonstrated. The input function prompts users for input values stored in variables.
• Is more intelligent than human ???
– Of course Not!
• A slave that only does what it is told
• Is always right; can never be wrong
• Good at performing lengthy and recurring tasks
The slides for a lecture about the Ruby programming language. This language was given at FEUP, on a course called "Laboratories of Object-Oriented Programming".
This document discusses using inheritance versus interfaces to model cat behavior in an object-oriented simulation. It describes how inheritance leads to maintenance issues when requirements change. The document proposes using interfaces to separate behaviors that may vary (eating, purring) from the cat class. This allows different concrete behavior classes to be composed into cat objects at runtime. The strategy pattern is applied to make behaviors pluggable and avoid tight coupling between behaviors and cats. Overall this improves flexibility, maintainability and reuse when requirements change.
[YIDLUG] Programming Languages Differences, The Underlying Implementation 1 of 2Yo Halb
Algebra allows representing mathematical relationships with variables in a standardized way. It provides benefits like readability through use of variables and easier calculation by setting up equations to solve for unknown values. Boolean algebra applies the same concepts to true/false values where true is represented by 1 and false by 0. Computer programming languages leverage algebraic concepts with functions, variables, equations, and Boolean logic to solve problems.
The Functional Programmer's Toolkit (NDC London 2019)Scott Wlaschin
(slides and video at https://fsharpforfunandprofit.com/fptoolkit)
The functional programming community has a number of patterns with strange names such as monads, monoids, functors, and catamorphisms.
In this beginner-friendly talk, we'll demystify these techniques and see how they all fit together into a small but versatile "tool kit".
We'll then see how the tools in this tool kit can be applied to a wide variety of programming problems, such as handling missing data, working with lists, and implementing the functional equivalent of dependency injection.
Learn Polymorphism in Python with Examples.pdfDatacademy.ai
In Python, polymorphisms refer to the occurrence of something in multiple forms. As part of polymorphism, a Python child class has methods with the same name as a parent class method. This is an essential part of programming. A single type of entity is used to represent a variety of types in different contexts (methods, operators, objects, etc.)
visit by :-https://www.datacademy.ai/learn-polymorphism-python-examples/
This document provides an overview of object-oriented programming concepts including classes, objects, inheritance, abstraction, encapsulation, and polymorphism. It defines OOP as an engineering approach for building software systems based on modeling real-world entities as classes and objects that exchange messages. Key concepts are explained such as classes defining attributes and behaviors of objects, objects being instances of classes, and communication between objects occurring through messages. The four main principles of OOP - inheritance, abstraction, encapsulation, and polymorphism - are also summarized.
This document provides an overview of the lessons and content covered in Module 3 of an online coding curriculum. It outlines four lessons on variables, strings, and networks/the internet. The lessons introduce key concepts like variables, data types, strings, methods, and network protocols. They include warm-up activities, gameplay in the coding game Ozaria to reinforce concepts, and extension activities. The document provides guidance for teachers on preparing for and teaching the lessons, which combine presentation of concepts with hands-on practice and checkpoints for student understanding.
Python Homework Help has the best homework help experts for your academic homework. Our Python experts hold Ph.D. degrees and can help you in preparing accurate solutions and answers for your Python homework questions. Our panel of online Python experts will help you get your basics right in order to understand and tackle difficult problems.
Reach out to our team via: -
Website: - https://www.pythonhomeworkhelp.com/
Email: support@pythonhomeworkhelp.com
Call/WhatsApp: +1(315)557–6473
We provide the best Python Homework Help online, and we guarantee that the clients get the highest score. We can work in a short time duration by maintaining the quality of work. Your deadline becomes our priority when you hire us!
Reach out to our team via: -
Website: - https://www.pythonhomeworkhelp.com/
Email: support@pythonhomeworkhelp.com
Call/WhatsApp: +1(315)557–6473
From the 2017 HPCC Systems Community Day:
Roger Dev gives an update on the new algorithms and other innovative features in our machine learning library.
Roger Dev
Senior Architect, LexisNexis Risk Solutions
Roger is a Senior Architect working with John Holt on the Machine Learning Team. He recently joined HPCC Systems from CA Technologies. Roger has been involved in the implementation and utilization of machine learning and AI techniques for many years, and has over 20 patents in diverse areas of software technology.
Build a virtual pet with javascript (april 2017)Thinkful
This document provides an overview of building a virtual pet game using JavaScript. It introduces JavaScript concepts like variables, objects, functions, and conditional statements. It outlines the goals of building a functional pet game to practice programming skills and covers specific coding challenges like adding properties to a pet object and writing functions to feed and exercise the pet. The document also provides context on JavaScript and programming in general.
LESSON 3A. INTRODUCTION TO ITERATION: LOOPS, TRACE TABLES, WHILE LOOPS
Introduction to Iteration and loops. The theory behind loops and how they work. Create and adapt programs using loops. Intro to the random number generator. Learn about trace tabling (white box testing). Example of a trace table and dry run. Wonders of the Fibonacci sequence. Examples of Iteration in game design. Focus on While loops. Challenges, tasks (with solutions), suggested videos, big ideas discussion and research and HW included. Introducing Ada Lovelace and Charles Babbage.
The document discusses principles and best practices for writing high-quality code, including keeping code simple, avoiding duplication, using object-oriented design principles like SOLID, giving variables and methods meaningful names, properly structuring classes, methods and variables, and applying principles of encapsulation and inheritance. It emphasizes that code quality is important to reduce development costs and improve productivity.
Java is an object-oriented programming language and platform. It uses a virtual machine (JVM) to run bytecode, making Java programs platform independent. The JVM handles memory management through garbage collection. Java uses classes and objects to implement OOP concepts. Variables are declared with a specific primitive data type or class type. Java supports control flow statements like if/else and loops. Arrays allow storing multiple values of the same type. Methods define reusable blocks of code that can operate on objects.
This document provides an introduction to object-oriented programming (OOP) concepts. It discusses procedural programming and its limitations. OOP aims to overcome these limitations through concepts like encapsulation, inheritance, polymorphism, and abstraction. Encapsulation binds data and functions together in classes. Inheritance allows deriving new classes from existing classes. Polymorphism allows the same action to be performed in different ways. Abstraction describes things at a conceptual level. Examples are provided to illustrate these core OOP concepts. The next lecture will cover implementing OOP in C# and building a game with Unity 3D.
SI is supplemental instruction led by Caleb Peacock to help develop study skills. Variables are used to store and reference values in code. There are different data types like integers, floats, and strings. Variables must start with a letter or underscore and can include numbers and underscores but no spaces. Constant variables store fixed values in all caps. Comments describe code and are preceded by #. Basic math operations and mixing data types were demonstrated. The input function prompts users for input values stored in variables.
Philippine Edukasyong Pantahanan at Pangkabuhayan (EPP) CurriculumMJDuyan
(𝐓𝐋𝐄 𝟏𝟎𝟎) (𝐋𝐞𝐬𝐬𝐨𝐧 𝟏)-𝐏𝐫𝐞𝐥𝐢𝐦𝐬
𝐃𝐢𝐬𝐜𝐮𝐬𝐬 𝐭𝐡𝐞 𝐄𝐏𝐏 𝐂𝐮𝐫𝐫𝐢𝐜𝐮𝐥𝐮𝐦 𝐢𝐧 𝐭𝐡𝐞 𝐏𝐡𝐢𝐥𝐢𝐩𝐩𝐢𝐧𝐞𝐬:
- Understand the goals and objectives of the Edukasyong Pantahanan at Pangkabuhayan (EPP) curriculum, recognizing its importance in fostering practical life skills and values among students. Students will also be able to identify the key components and subjects covered, such as agriculture, home economics, industrial arts, and information and communication technology.
𝐄𝐱𝐩𝐥𝐚𝐢𝐧 𝐭𝐡𝐞 𝐍𝐚𝐭𝐮𝐫𝐞 𝐚𝐧𝐝 𝐒𝐜𝐨𝐩𝐞 𝐨𝐟 𝐚𝐧 𝐄𝐧𝐭𝐫𝐞𝐩𝐫𝐞𝐧𝐞𝐮𝐫:
-Define entrepreneurship, distinguishing it from general business activities by emphasizing its focus on innovation, risk-taking, and value creation. Students will describe the characteristics and traits of successful entrepreneurs, including their roles and responsibilities, and discuss the broader economic and social impacts of entrepreneurial activities on both local and global scales.
How to Make a Field Mandatory in Odoo 17Celine George
In Odoo, making a field required can be done through both Python code and XML views. When you set the required attribute to True in Python code, it makes the field required across all views where it's used. Conversely, when you set the required attribute in XML views, it makes the field required only in the context of that particular view.
Main Java[All of the Base Concepts}.docxadhitya5119
This is part 1 of my Java Learning Journey. This Contains Custom methods, classes, constructors, packages, multithreading , try- catch block, finally block and more.
This document provides an overview of wound healing, its functions, stages, mechanisms, factors affecting it, and complications.
A wound is a break in the integrity of the skin or tissues, which may be associated with disruption of the structure and function.
Healing is the body’s response to injury in an attempt to restore normal structure and functions.
Healing can occur in two ways: Regeneration and Repair
There are 4 phases of wound healing: hemostasis, inflammation, proliferation, and remodeling. This document also describes the mechanism of wound healing. Factors that affect healing include infection, uncontrolled diabetes, poor nutrition, age, anemia, the presence of foreign bodies, etc.
Complications of wound healing like infection, hyperpigmentation of scar, contractures, and keloid formation.
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...PECB
Denis is a dynamic and results-driven Chief Information Officer (CIO) with a distinguished career spanning information systems analysis and technical project management. With a proven track record of spearheading the design and delivery of cutting-edge Information Management solutions, he has consistently elevated business operations, streamlined reporting functions, and maximized process efficiency.
Certified as an ISO/IEC 27001: Information Security Management Systems (ISMS) Lead Implementer, Data Protection Officer, and Cyber Risks Analyst, Denis brings a heightened focus on data security, privacy, and cyber resilience to every endeavor.
His expertise extends across a diverse spectrum of reporting, database, and web development applications, underpinned by an exceptional grasp of data storage and virtualization technologies. His proficiency in application testing, database administration, and data cleansing ensures seamless execution of complex projects.
What sets Denis apart is his comprehensive understanding of Business and Systems Analysis technologies, honed through involvement in all phases of the Software Development Lifecycle (SDLC). From meticulous requirements gathering to precise analysis, innovative design, rigorous development, thorough testing, and successful implementation, he has consistently delivered exceptional results.
Throughout his career, he has taken on multifaceted roles, from leading technical project management teams to owning solutions that drive operational excellence. His conscientious and proactive approach is unwavering, whether he is working independently or collaboratively within a team. His ability to connect with colleagues on a personal level underscores his commitment to fostering a harmonious and productive workplace environment.
Date: May 29, 2024
Tags: Information Security, ISO/IEC 27001, ISO/IEC 42001, Artificial Intelligence, GDPR
-------------------------------------------------------------------------------
Find out more about ISO training and certification services
Training: ISO/IEC 27001 Information Security Management System - EN | PECB
ISO/IEC 42001 Artificial Intelligence Management System - EN | PECB
General Data Protection Regulation (GDPR) - Training Courses - EN | PECB
Webinars: https://pecb.com/webinars
Article: https://pecb.com/article
-------------------------------------------------------------------------------
For more information about PECB:
Website: https://pecb.com/
LinkedIn: https://www.linkedin.com/company/pecb/
Facebook: https://www.facebook.com/PECBInternational/
Slideshare: http://www.slideshare.net/PECBCERTIFICATION
it describes the bony anatomy including the femoral head , acetabulum, labrum . also discusses the capsule , ligaments . muscle that act on the hip joint and the range of motion are outlined. factors affecting hip joint stability and weight transmission through the joint are summarized.
2. Announcements
• Office Hours next Tuesday, April 4, 2000 will be
from 1:00 - 2:00 p.m. instead of 3:00 - 4:00 p.m.
• On the homework that’s due Friday
– Problem 2 requires inheritance!
LB
4. Scenarios
• A veterinarian's algorithm might have a list of
animals, but each one needs different food or
care… we want ONE information system to track
all of this without complex logic for each
individual kind of animal.
• A car dealership sells many different types of
cars with different features, but each has a price
and quantity in stock.
• A registration system might treat in-state
students differently from out-of-state students,
graduate students differently from
undergraduates, etc.
• A graphical user interface (GUI) e.g. Windows
needs to puts lots of simlar widgets on screen...
LB
5. Motivation
• We’d like to be able to manage objects
of different kinds of classes.
• Since classes within a class hierarchy
often share common methods and
attributes, we’d like to make use of this
fact to make our algorithms simpler.
6. Polymorphism Defined
• The ability to take on different forms.
• Manipulate objects of various classes,
and invoke methods on an object
without knowing that object’s type.
9. Polymorphism Explained
MyAnimal <- MyMutt seems incorrect. The left
and right hand side of the assignment seem to
not match; or do they?
Since Mutt inherits from Dog, and Dog inherits from
Animal, then MyMutt is at all times a Mutt, a Dog,
and an Animal. Thus the assignment statement is
perfectly valid.
This makes logical (“real world”) sense.
10. An Illegal Example
• We are able to assign an object of a sub-
class into an object of a super-class as in:
MyAnimal <- MyMutt
• But the reverse is not true. We can’t
assign a superclass object into a sub-
class object.
MyMutt <- MyAnimal // illegal
11. Method Calls and Polymorphism
Assume the Dog class inherits the Animal
class, redefining the “MakeNoise” method.
Consider the following:
MyAnimal <- MyDog
MyAnimal.MakeNoise
12. Method Calls and Polymorphism
MyAnimal <- MyDog
MyAnimal.MakeNoise
Different languages handle this differently.
For simplicity, we’ll assume that MyAnimal
“remembers” it is actually an object of
the Dog class, so we’ll execute the
MakeNoise method in the Dog class.
13. Polymorphism vs. Inheritance
• Inheritance is required in order to
achieve polymorphism (we must have
class hierarchies).
– Re-using class definitions via
extension and redefinition
• Polymorphism is not required in order
to achieve inheritance.
– An object of class A acts as an
object of class B (an ancestor to A).
14. Processing Collections
• One of the main benefits of polymorphism
is the ability to easily process collections.
• We will consider a collection (queue) of
bank accounts in the next example. . .
15. The Banking Class Hierarchy
Cool Savings
Bank
Account
Savings
Account
Checking
Account
NOW
Account
Money Market
Account
CD Account
16. A Collection of Bank Accounts
Imagine a bank needs to manage all of the
accounts.
Rather than maintain seven separate queues, one
each for: Bank_Accounts, Savings_Accounts,
Cool_Savings, CD_Accounts,
Checking_Accounts, NOW_accounts, and
Money_Market_Accounts
We can maintain only one queue of Bank Accounts.
17. Polymorphic Banking
Assume accounts of various kinds:
john_account isoftype Checking_Account
paul_account isoftype Cool_Savings
paul_other_account isoftype CD_Account
george_account isoftype NOW_Account
ringo_account isoftype Money_Market
Then put them all in a single structure:
account_queue isoftype Queue(Bank_Account)
account_queue.Enqueue(john_account)
account_queue.Enqueue(paul_account)
account_queue.Enqueue(paul_other_account)
account_queue.Enqueue(george_account)
account_queue.Enqueue(ringo_account)
18. Polymorphic Banking
account_queue is polymorphic:
• It is holding accounts of “many forms.”
• Each of the accounts is “within the family”
of the class hierarchy of bank accounts.
• Each one will have it’s own set of
capabilities via inheritance (extension,
and/or redefinition).
19. Example of Polymorphic Banking
With polymorphism, our main algorithm doesn’t care what
kind of account it is processing
sum, amount isoftype Num
account isoftype Bank_Account
account_queue isoftype Queue(Bank_Account)
. . .
sum <- 0
loop
exitif( account_queue.IsEmpty )
account_queue.Dequeue( account )
sum <- sum + account.Get_Balance
endloop
print( “Sum of the balances is: ”, sum )
20. Resolving Polymorphic Method Calls
• Different languages do this differently.
• The various kinds of Accounts, though all stored
as a Bank_Account, remember the class
(subclass) of which they are an instance.
• So, calls to Get_Balance() will:
– use the method from class NOW_Account if
the object is an instance of NOW_Account
– use the method from class Money_Market if
the object is an instance of Money_Market
– and so on...
21. Polymorphism
• This is the “magic” of polymorphism…it keeps
track of family members within the inheritance
hierarchy for you.
• Without it, we’d have lots of code sprinkled
through out our algorithm choosing among many
options:
if( it’s Checking_Account ) then
call Checking_Account Calc_Interest
elseif( it’s Super_Savings) then
call Super_Savings Calc_Interest
elseif( it’s CD_Account then
call CD_Account Calc_Interest
elseif( it’s NOW_Account ) then
call NOW_Account Calc_Interest
. . .
22. Summary
• Polymorphism allows objects to represent
instances of its own class and any of its
sublcasses.
• Polymorphic collections are useful for managing
objects with common (ancestor) interfaces.
• For our purposes, we’ll assume objects
“remember” what kind of class they really
contain, so method calls are resolved to the
original class.
25. What Have We Discussed?
• Structured programming
• Object-Oriented programming
What’s left?
• Everything an object…
• Let’s make a class coordinate activities
26. Structured Programming
• Break down the problem.
• Each module has a well-defined interface
of parameters
• A main algorithm calls and coordinates
the various modules; the main is “in
charge.”
• Persistent data (in the main algorithm) vs.
module data (dies upon module
completion).
27. An Example
Let’s write an algorithm to simulate a veterinarian’s
clinic…
• Maintain a collection of different animals
• Feed, water, talk with and house animals
• Allow owners to bring pets for treatment and
boarding
• We’ll present a menu of options to the user
28. A Structured Solution
• Write many record types (cat, dog, rabbit)
• Write the collection records and modules
for each type of pet
• Write many modules allowing for
interactions with the collection
• Write menu and processing modules
• Write main algorithm
29. An Object-Oriented Solution
• Write class hierarchy with inheritance (pet,
cat, dog, rabbit)
• Write the generic collection class
• Write many modules allowing for
interactions with the collection
• Write menu and processing modules
• Write main algorithm
30. Simulating a Veterinarian Clinic
Boarding Pens
(Vector)
Vet Clinic
Dog
Cat
Rabbit
Pet
Owner
(user)
is-a
is-a
is-a
has-a
has-a
user
interaction
LB
33. procedure PrintMenu
print(“Please enter a choice:”)
print(“ADD a pet”)
print(“REMOVE a pet”)
print(“FEED pets”)
print(“LIST pets”)
...
print(“QUIT”)
endprocedure // PrintMenu
procedure GetChoice(choice isoftype out string)
print(“What would you like to do?”)
read(choice)
endprocedure // GetChoice
LB
34. procedure ProcessChoice(choice iot in string,
Pens iot in/out Vector(Pet))
if (choice = “ADD”) then
AddPet(Pens)
elseif (choice = “REMOVE”) then
RemovePet(Pens)
elseif (choice = “FEED”) then
FeedPets(Pens)
elseif (choice = “LIST”) then
. . .
endif
endprocedure // ProcessChoice
LB
35. procedure RemovePet(Pens iot in/out Vector(Pet))
IndexToRemove isoftype num
print(“What is the index of the pet to remove?”)
read(IndexToRemove)
if (IndexToRemove <= Pens.SizeOf) then
Pens.RemoveElementAt(IndexToRemove)
else
print(“ERROR: That index is too high”)
endif
endprocedure // RemovePet
36. procedure FeedPets(Pens iot in/out Vector(Pet))
count isoftype num
count <- 1
loop
exitif(count > Pens.SizeOf)
// get the next pet in the collection and
// polymorphically call the Eat method on
// that pet (whatever its class)
Pens.ElementAt(count).Eat
count <- count + 1
endloop
print(“Pets all fed!”)
endprocedure // FeedPets
37. . . . continue implementation
AddPet module, etc.
38. Vestiges of Structured Programming
• In the previous example (and thus far), we
have used classes and objects in the
conventional structured approach to
algorithms that we have used throughout.
• We have done what is called Hybrid OO:
“the use of OO constructs within the
standard structured paradigm.”
• What is the difference?
39. Hybrid Object-Oriented Programming
• “Hybrid OO” is like Structured in some
ways:
– Break down the problem.
– One module per sub-problem.
– Each module has one task.
– Each module has a interface of
parameters.
– A main algorithm is “in charge” of
program.
40. Hybrid Object-Oriented Programming
• “Hybrid OO” is not just like structured:
• Each object maintains it’s own persistent data.
• Uses OO constructs (classes & objects):
– Encapsulate data and methods together
– Support data integrity by protecting data
– Reuse, minimizing recreating code
– Inheritance to ease customization
– Polymorphism to model the world
• Our examples so far show Hybrid OO:
– Structured algorithms, main in charge.
– Use of OO constructs (classes & objects)
41. What’s Left?
• The Object-Oriented paradigm is state of the art:
– Encapsulation
– Reusability/Adaptability
– Polymorphism
• But what’s left?
– The algorithm itself…
– We still have a main algorithm in control
42. class VetClinic
uses Vector, Pet, Cat, Dog, Rabbit
public
procedure Initialize
// contract here
protected
Pens isoftype Vector(Pet)
procedure Initialize
Pens.Initialize
DoWork
endprocedure // Initialize
43. // Still in protected section
procedure DoWork
// contract here – protected method
choice isoftype string
loop
PrintMenu
GetChoice(choice)
exitif (choice = “QUIT”)
ProcessChoice(choice)
endloop
print(“The Vet Clinic has closed.”)
endprocedure // DoWork
44. // Still in protected section
procedure PrintMenu
// contract here – protected method
print(“Please enter a choice:”)
print(“ADD a pet”)
print(“REMOVE a pet”)
print(“FEED pets”)
. . .
print(“QUIT”)
endprocedure // PrintMenu
procedure GetChoice(choice iot out string)
// contract here – protected method
print(“What would you like to do?”)
read(choice)
endprocedure // GetChoice
45. // Still in protected section
procedure ProcessChoice(choice iot in string)
// contract here – protected method
if (choice = “ADD”) then
AddPet
elseif (choice = “REMOVE”) then
RemovePet
elseif (choice = “FEED”) then
FeedPets
. . .
endif
endprocedure // ProcessChoice
46. // Still in protected section
procedure RemovePet
// contract here – protected method
IndexToRemove isoftype num
print(“What is index of the pet to remove?”)
read(IndexToRemove)
if (IndexToRemove <= Pens.Size) then
Pens.RemoveElementAt(IndexToRemove)
else
print(“ERROR: That index is too high”)
endif
endprocedure // RemovePet
47. // Still in protected section
procedure FeedPets
// contract here – protected method
count isoftype num
count <- 1
loop
exitif(count > Pens.Size)
// get the next pet in the collection and
// polymorphically call the Eat method on
// that pet (whatever its class)
Pens.ElementAt(count).Eat
count <- count + 1
endloop
print(“Pets all fed!”)
endprocedure // FeedPets
48. // Still in protected section
. . . continue the protected methods
endclass // VetClinic
// --------------------------------------
algorithm VetExample
store isoftype VetClinic
store.Initialize
endalgorithm // VetExample
49. What Did We Do?
• Everything is an object
• The main algorithm (if it exists at all) simply
creates a VetClinic and calls its Initialize method.
• From there, the VetClinic object coordinates the
system
• Now we’re doing Pure OO Programming
50. Pure Object Oriented Programming
• There is no main algorithm in charge.
• Control is decentralized among various objects.
• Everything in the program is an object.
• A root class “gets things started.”
• The root class is not “in charge”; instead it
invokes some method, beginning a chain reaction
of objects calling methods provided by other
objects.
• Requires a slightly different way of thinking:
centralized control vs. distributed control.
59. Typical Operations
Class AddButton inherits Button
...
Procedure Listen
// Activated when mouse button pressed
ResultBox.SetContents(
TopBox.GetContents +
BottomBox.GetContents)
endprocedure
This type method “listens”
for an event to occur
LB
61. Typical Operations
Class CalcWindow inherits Window
...
Procedure Initialize
// Starts everything up
super.Initialize
AddIn(ClearButton)
AddIn(AddButton)
AddIn(TopBox)
AddIn(BottomBox)
AddIn(ResultBox)
endprocedure
Where the buttons and boxes
are located is magic
LB
62. Starting it all up
theWindow isoftype CalcWindow
theWindow.ShowAt(LOCX, LOCY)
This code would appear in some
kind of special initiation construct:
A root class or a startup main or whatever.
LB
64. A Vehicle Dealership Example
Queue of Vehicles
Car Truck
Dealership
User/Customer
65. Other Pure OO Examples
• Interactive programs
• Graphical, windowed interfaces
– Mac OS, Windows, etc.
• Event-driven programming
• Complex database applications
66. Summary of Structured Programming
• Break down the problem.
• One module per sub-problem.
• Each module has one task.
• Each module has a interface of
parameters.
• A main algorithm is “in charge” of
program.
• Local data dies, must pass back to main.
67. Summary of Hybrid- vs. Pure-OO
• Hybrid-OO programming means:
– Structured algorithms, main in charge.
– Use of OO constructs (classes-&-
objects)
• Pure-OO or Real-OO programming means:
– No main in charge.
– Decentralized, distributed control.
– Everything is an object.
69. Pseudocode to Java
class Simple
public
Procedure Initialize()
// PPP
procedure setValue(newVal isoftype in Num)
// ppp
function getValue returnsa Num()
// PPP
LB
70. Pseudocode to Java
protected
value isoftype Num
Procedure Initialize()
value <- 0
endprocedure
procedure setValue(newVal isoftype in Num)
value <- newVal
endprocedure
function getValue returnsa Num()
getValue returns value
endfunction
endclass
LB
71. Java version
class Simple {
private int value;
// ppp
public void Simple() {
value = 0;
} // Constructor
// ppp
public setValue(int newVal) {
value = newVal;
} // setValue
// ppp
public int getValue() {
return value;
} // getValue
} // Simple
LB