Function Objects and Comparators

Slides:



Advertisements
Similar presentations
JAVA Revision Lecture Electronic Voting System Marina De Vos.
Advertisements

Advanced XSLT II. Iteration in XSLT we sometimes wish to apply the same transform to a set of nodes we iterate through a node set the node set is defined.
Dana Shapira Hash Tables
Testability Calculation Team member: Gefu Xu Yueli Liu Weidong Tang.
Basic Definitions Data Structures: Data Structures: A data structure is a systematic way of organizing and accessing data. Or, It’s the logical relationship.
Selection Sort
The Dog and the Mailman Project 1. Simulate Mailmen and Dogs Dog sees mailman Mailman sees dog Mailman runs from dog Dog runs to bite mailman (or get.
The Binary Search Textbook Authors: Ken Lambert & Doug Nance PowerPoint Lecture by Dave Clausen
Computers & Logic An Overview. Hardware Hardware is the equipment, or the devices, associated with a computer. For a computer to be useful, however, it.
Lists and More About Strings CS303E: Elements of Computers and Programming.
Programming History. Who was the first programmer?
Chapter 6 Object-Oriented Java Script JavaScript, Third Edition.
Computer Science 1MD3 Introduction to Programming
Objectives - 11  We will work with processing Arrays.  Objectives:  Describe the concept of an array and its benefits.  Define the terms index, traverse,
Object-Oriented Design Simple Program Design Third Edition A Step-by-Step Approach 11.
Selection Sort
Lists in Python Selection Sort Algorithm. Sorting A very common activity for computers Not just in business, sorting is used in databases, graphics, simulations,
CS 111 – Nov. 5 Sorting –Selection and Bubble √ –insertion: place next element in correct place by shifting over other ones to make space –Merge: Repeatedly.
CSI 3125, Preliminaries, page 1 Data Type, Variables.
Even and Odd SYMMETRY Suppose f is continuous on [-a, a] and even Suppose f is continuous on [-a, a] and odd.
Lists in Python Lists as Arguments/Parameters. Lists as arguments to functions Just like other data types, lists can be sent to functions as arguments.
Introduction to.NET Florin Olariu “Alexandru Ioan Cuza”, University of Iai Department of Computer Science.
Website Source Code Free Download.
The Expression Language Syntax
The Object-Oriented Thought Process Chapter 03
Unit II-Chapter No. : 5- design Patterns
Java Language Basics.
Pixy Python API Charlotte Weaver.
Data Virtualization Demoette… Custom Java Procedures
Basic-Algorithms-of-Bioinformatics Applet
Mobile applications Jouni Juntunen Oulu University of Applied Sciences
Recitation 6.
..,../' CJ " · "' ; '..
The relational operators
Copyright © Cengage Learning. All rights reserved.
© Akhilesh Bajaj, All rights reserved.
SLOPE = = = The SLOPE of a line is There are four types of slopes
Computers & Programming Languages
EXTENSION AND INTEGRATION
Coding Concepts (Sub- Programs)
Passing Parameters by value
Straight Selection Sort
-­,-­, '.-.- ·'·' '·..'·..... '-.: - - (p - C!J " 1.,.c_.. If ( '.. ' " ' ' " ' I.
CSCI 3333 Data Structures Array
Chapter 8 Collection Types.
Rational Rose 2018/12/30.
Compound Statements A Quick Overview
Factory Pattern.
Parameter Passing in Java
Ken Lambert & Doug Nance
Unit 6 part 3 Test Javascript Test.
Unit 6 part 2 Test Javascript Test.
Array?.
Multiple Inheritance in C++
Sorting Example Bubble Sort
Lecture 8: Complex Linked List Code reading: 16.2 – 16.3
ICT Programming Lesson 1:
Unit 6 part 5 Test Javascript Test.
Lesson 2: Cell References
ENIAC – the first computer
Collaborative Open Source Web Applications
The Binary Search by Mr. Dave Clausen
What is Programming Language
Winter 2019 CISC101 5/26/2019 CISC101 Reminders
CMPT 120 Lecture 19 – Unit 3 – Graphics and Animation
Web Application Development Using PHP
Functions What is a function? What are the different ways to represent a function?
Keyword Arguments aka Named Parameters in Ruby (and Python)
Introduction to Computer Science
Presentation transcript:

Function Objects and Comparators Nicholas Allen, Benjamin Stevens, CJ Miller

Why Do we Need Function Objects? In many coding languages such as Python, JavaScript, and Perl, functions can be treated as objects and passed as a parameter to another function. However this is not possible in Java, thus the code to the right is incorrect.

A New Approach Instead what we need to do is wrap our function inside of a single method “Function Object”

Result We can now pass our newly created function object to another function, giving that function access to the method wrapped within the function object.

Example Suppose we were to make a four function calculator using function objects We would first create an interface with one method defined

In Class Demo Now we need four volunteers to represent function objects for our four functions and one volunteer to be our class that is passed the function objects

Comparators Unique type of function object is a comparator, which allows you to define rules to determine whether an element comes logically before or after another element. These are primarily used in sorting algorithms for elements that can be sorted in a number of ways.

Coding Demo