This document discusses container classes in object-oriented programming. It examines tensions between strong typing and reuse in statically typed languages. Three approaches are presented to address this issue: using substitution and downcasting, substitution and overriding, and generics. Iterators and visitors are also discussed as solutions for traversing container elements without exposing internal structures.
Lara Technologies are providing Software Training Division, Java/J2ee, Android, Web Services, Logical Coding, Basics Of C Language, Soft Skills, Aptitude, Etc.
(7) c sharp introduction_advanvced_features_part_iiNico Ludwig
This presentation comes with many additional notes (pdf): http://de.slideshare.net/nicolayludwig/7-c-sharp-introductionadvanvcedfeaturespartii-38640489
Check out these exercises: http://de.slideshare.net/nicolayludwig/6-7-c-sharp-introductionadvancedfeaturespartipartiiexercises
- Object-based and generic Collections
- Delegates and Events
- Custom Attributes
- Reflection
Lara Technologies are providing Software Training Division, Java/J2ee, Android, Web Services, Logical Coding, Basics Of C Language, Soft Skills, Aptitude, Etc.
(7) c sharp introduction_advanvced_features_part_iiNico Ludwig
This presentation comes with many additional notes (pdf): http://de.slideshare.net/nicolayludwig/7-c-sharp-introductionadvanvcedfeaturespartii-38640489
Check out these exercises: http://de.slideshare.net/nicolayludwig/6-7-c-sharp-introductionadvancedfeaturespartipartiiexercises
- Object-based and generic Collections
- Delegates and Events
- Custom Attributes
- Reflection
Kotlin advanced - language reference for android developersBartosz Kosarzycki
StxNext Lightning Talks - Mar 11, 2016
Kotlin Advanced - language reference for Android developers
This presentation contains the second talk on Kotlin language we had at STXNext. We try go deeper into language specifics and look at the positive impact new syntax can have on boilerplate removal and readability improvement.
Kotlin really shines in Android development when one looks at “Enum translation”, “Extension functions”, “SAM conversions”, “Infix notation”, “Closures” and “Fluent interfaces” applied to lists. The talk, however, compares language-specifics of Java & Kotlin in terms of “Type Variance”, “Generics” and “IDE tools” as well.
We present real-world example based on Stx-Insider project written in Kotlin which incorporates Dagger 2, Kotterknife, Retrofit2 and is composed of 5+ Activities.
Full agenda
Live templates
Enum translation
Calling extension functions from Kotlin/Java
Constructors with backing fields
Warnings
F-bound polymorphism
Variance (Covariance/Contravariance)
Variance comparison in Kotlin/Java/Scala
Annotation processing - KAPT
SAM conversions
Type equality
Lambda vs Closure
Reified generics
Fluent interfaces
Infix notation
Static extension methods in Kotlin
Generic types
Sealed classes
Dokka - documentation in Kotlin
J2K converter
Real-world example
Reflection
Presentation is accompanied with an example project (StxInsider):
https://github.com/kosiara/stx-insider
Qcon2011 functions rockpresentation_scalaMichael Stal
This is the part I of the tutorial I planned to give at QCon 2011 on Functional Programming with Scala. It also includes Scala 2.8 as well as upcoming features
Esoft Metro Campus - Diploma in Web Engineering - (Module V) Programming with JavaScript
(Template - Virtusa Corporate)
Contents:
Introduction to JavaScript
What JavaScript Can Do?
Script tag in HTML
Noscript tag in HTML
Your First JavaScript Program
JavaScript Placement in HTML File
JavaScript Syntax
JavaScript Data Types
JavaScript Variables
JavaScript Identifiers
Arithmetic Operators
String Concatenation Operators
Assignment Operators
Comparison Operators
Logical Operators
Bitwise Operators
If Statement
If… Else Statement
If… Else if… Else Statement
Switch Statement
The ? Operator
While Loop
Do While Loop
For Loop
For…in Loop
break Statement
continue Statement
Arrays
Functions
JavaScript Objects
JavaScript Scope
Strings
Regular Expressions
JavaScript Numbers
Math Object
Date and Time
JavaScript Events
Dialog Boxes
Error Handling in JavaScript
JavaScript Forms Validation
JavaScript HTML DOM
JavaScript BOM
This presentation introduces some advanced concepts of generics in Java. These slides introduce the following concepts:
- Generic classes and methods
- Type variable bounds
- Type erasure process
- Generics and inheritance
- Wildcard types
The presentation is took from the Java course I run in the bachelor-level informatics curriculum at the University of Padova.
JavaScript and popular programming paradigms (OOP, AOP, FP, DSL). Overview of the language to see what tools we can leverage to reduce complexity of our projects.
This part goes over language features and looks at OOP and AOP with JavaScript.
The presentation was delivered at ClubAJAX on 2/2/2010.
Blog post: http://lazutkin.com/blog/2010/feb/5/exciting-js-1/
Continued in Part II: http://www.slideshare.net/elazutkin/exciting-javascript-part-ii
Logic-based program transformation in symbiosis with EclipseCoen De Roover
"Logic-based program transformation in symbiosis with Eclipse" as presented at the 2011 Seminar Series on Advanced Techniques & Tools for Software Evolution in Koblenz.
Java Serialization is often considered a dark art of Java programmers. This session will lift the veil and show what serialization is and isn't, how you can use it for profit and evil. After this session no NotSerializableException will be unconquerable.
Kotlin advanced - language reference for android developersBartosz Kosarzycki
StxNext Lightning Talks - Mar 11, 2016
Kotlin Advanced - language reference for Android developers
This presentation contains the second talk on Kotlin language we had at STXNext. We try go deeper into language specifics and look at the positive impact new syntax can have on boilerplate removal and readability improvement.
Kotlin really shines in Android development when one looks at “Enum translation”, “Extension functions”, “SAM conversions”, “Infix notation”, “Closures” and “Fluent interfaces” applied to lists. The talk, however, compares language-specifics of Java & Kotlin in terms of “Type Variance”, “Generics” and “IDE tools” as well.
We present real-world example based on Stx-Insider project written in Kotlin which incorporates Dagger 2, Kotterknife, Retrofit2 and is composed of 5+ Activities.
Full agenda
Live templates
Enum translation
Calling extension functions from Kotlin/Java
Constructors with backing fields
Warnings
F-bound polymorphism
Variance (Covariance/Contravariance)
Variance comparison in Kotlin/Java/Scala
Annotation processing - KAPT
SAM conversions
Type equality
Lambda vs Closure
Reified generics
Fluent interfaces
Infix notation
Static extension methods in Kotlin
Generic types
Sealed classes
Dokka - documentation in Kotlin
J2K converter
Real-world example
Reflection
Presentation is accompanied with an example project (StxInsider):
https://github.com/kosiara/stx-insider
Qcon2011 functions rockpresentation_scalaMichael Stal
This is the part I of the tutorial I planned to give at QCon 2011 on Functional Programming with Scala. It also includes Scala 2.8 as well as upcoming features
Esoft Metro Campus - Diploma in Web Engineering - (Module V) Programming with JavaScript
(Template - Virtusa Corporate)
Contents:
Introduction to JavaScript
What JavaScript Can Do?
Script tag in HTML
Noscript tag in HTML
Your First JavaScript Program
JavaScript Placement in HTML File
JavaScript Syntax
JavaScript Data Types
JavaScript Variables
JavaScript Identifiers
Arithmetic Operators
String Concatenation Operators
Assignment Operators
Comparison Operators
Logical Operators
Bitwise Operators
If Statement
If… Else Statement
If… Else if… Else Statement
Switch Statement
The ? Operator
While Loop
Do While Loop
For Loop
For…in Loop
break Statement
continue Statement
Arrays
Functions
JavaScript Objects
JavaScript Scope
Strings
Regular Expressions
JavaScript Numbers
Math Object
Date and Time
JavaScript Events
Dialog Boxes
Error Handling in JavaScript
JavaScript Forms Validation
JavaScript HTML DOM
JavaScript BOM
This presentation introduces some advanced concepts of generics in Java. These slides introduce the following concepts:
- Generic classes and methods
- Type variable bounds
- Type erasure process
- Generics and inheritance
- Wildcard types
The presentation is took from the Java course I run in the bachelor-level informatics curriculum at the University of Padova.
JavaScript and popular programming paradigms (OOP, AOP, FP, DSL). Overview of the language to see what tools we can leverage to reduce complexity of our projects.
This part goes over language features and looks at OOP and AOP with JavaScript.
The presentation was delivered at ClubAJAX on 2/2/2010.
Blog post: http://lazutkin.com/blog/2010/feb/5/exciting-js-1/
Continued in Part II: http://www.slideshare.net/elazutkin/exciting-javascript-part-ii
Logic-based program transformation in symbiosis with EclipseCoen De Roover
"Logic-based program transformation in symbiosis with Eclipse" as presented at the 2011 Seminar Series on Advanced Techniques & Tools for Software Evolution in Koblenz.
Java Serialization is often considered a dark art of Java programmers. This session will lift the veil and show what serialization is and isn't, how you can use it for profit and evil. After this session no NotSerializableException will be unconquerable.
Kotlin Advanced - language reference for Android developers STX Next
StxNext Lightning Talks - Mar 11, 2016
This presentation contains the second talk on Kotlin language we had at STXNext. We try go deeper into language specifics and look at the positive impact new syntax can have on boilerplate removal and readability improvement.
Kotlin really shines in Android development when one looks at “Enum translation”, “Extension functions”, “SAM conversions”, “Infix notation”, “Closures” and “Fluent interfaces” applied to lists. The talk, however, compares language-specifics of Java & Kotlin in terms of “Type Variance”, “Generics” and “IDE tools” as well.
We present real-world example based on Stx-Insider project written in Kotlin which incorporates Dagger 2, Kotterknife, Retrofit2 and is composed of 5+ Activities.
Slides from my "Swift, Swiftly" session at Øredev 2014.
Revealed by Apple in June of this year, the Swift programming language has already established itself as a huge leap forward for iOS and OS X developers. Learn the ins and outs of this new language, see how it compares to other modern OO languages, and hear about how Apple developers are using Swift to achieve new levels of productivity and efficiency.
Full video available: http://oredev.org/2014/sessions/swift-swiftly
Traits in Scala are similar to interfaces, but much more powerful.➢A trait encapsulates method and field definitions, which can then bereused by mixing them into classes.
This is inspired from Tom Mitchell's book on Machine Learning. You can achieve a bit exact implementation of the back propagation algorithm if you follow the code in this.
A simple client-server application in java in which a client sends a message to a server and the server tries to be funny by sending back a funny response.
Essentials of Automations: The Art of Triggers and Actions in FMESafe Software
In this second installment of our Essentials of Automations webinar series, we’ll explore the landscape of triggers and actions, guiding you through the nuances of authoring and adapting workspaces for seamless automations. Gain an understanding of the full spectrum of triggers and actions available in FME, empowering you to enhance your workspaces for efficient automation.
We’ll kick things off by showcasing the most commonly used event-based triggers, introducing you to various automation workflows like manual triggers, schedules, directory watchers, and more. Plus, see how these elements play out in real scenarios.
Whether you’re tweaking your current setup or building from the ground up, this session will arm you with the tools and insights needed to transform your FME usage into a powerhouse of productivity. Join us to discover effective strategies that simplify complex processes, enhancing your productivity and transforming your data management practices with FME. Let’s turn complexity into clarity and make your workspaces work wonders!
Check out the webinar slides to learn more about how XfilesPro transforms Salesforce document management by leveraging its world-class applications. For more details, please connect with sales@xfilespro.com
If you want to watch the on-demand webinar, please click here: https://www.xfilespro.com/webinars/salesforce-document-management-2-0-smarter-faster-better/
Top 7 Unique WhatsApp API Benefits | Saudi ArabiaYara Milbes
Discover the transformative power of the WhatsApp API in our latest SlideShare presentation, "Top 7 Unique WhatsApp API Benefits." In today's fast-paced digital era, effective communication is crucial for both personal and professional success. Whether you're a small business looking to enhance customer interactions or an individual seeking seamless communication with loved ones, the WhatsApp API offers robust capabilities that can significantly elevate your experience.
In this presentation, we delve into the top 7 distinctive benefits of the WhatsApp API, provided by the leading WhatsApp API service provider in Saudi Arabia. Learn how to streamline customer support, automate notifications, leverage rich media messaging, run scalable marketing campaigns, integrate secure payments, synchronize with CRM systems, and ensure enhanced security and privacy.
OpenMetadata Community Meeting - 5th June 2024OpenMetadata
The OpenMetadata Community Meeting was held on June 5th, 2024. In this meeting, we discussed about the data quality capabilities that are integrated with the Incident Manager, providing a complete solution to handle your data observability needs. Watch the end-to-end demo of the data quality features.
* How to run your own data quality framework
* What is the performance impact of running data quality frameworks
* How to run the test cases in your own ETL pipelines
* How the Incident Manager is integrated
* Get notified with alerts when test cases fail
Watch the meeting recording here - https://www.youtube.com/watch?v=UbNOje0kf6E
AI Pilot Review: The World’s First Virtual Assistant Marketing SuiteGoogle
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
👉👉 Click Here To Get More Info 👇👇
https://sumonreview.com/ai-pilot-review/
AI Pilot Review: Key Features
✅Deploy AI expert bots in Any Niche With Just A Click
✅With one keyword, generate complete funnels, websites, landing pages, and more.
✅More than 85 AI features are included in the AI pilot.
✅No setup or configuration; use your voice (like Siri) to do whatever you want.
✅You Can Use AI Pilot To Create your version of AI Pilot And Charge People For It…
✅ZERO Manual Work With AI Pilot. Never write, Design, Or Code Again.
✅ZERO Limits On Features Or Usages
✅Use Our AI-powered Traffic To Get Hundreds Of Customers
✅No Complicated Setup: Get Up And Running In 2 Minutes
✅99.99% Up-Time Guaranteed
✅30 Days Money-Back Guarantee
✅ZERO Upfront Cost
See My Other Reviews Article:
(1) TubeTrivia AI Review: https://sumonreview.com/tubetrivia-ai-review
(2) SocioWave Review: https://sumonreview.com/sociowave-review
(3) AI Partner & Profit Review: https://sumonreview.com/ai-partner-profit-review
(4) AI Ebook Suite Review: https://sumonreview.com/ai-ebook-suite-review
Software Engineering, Software Consulting, Tech Lead, Spring Boot, Spring Cloud, Spring Core, Spring JDBC, Spring Transaction, Spring MVC, OpenShift Cloud Platform, Kafka, REST, SOAP, LLD & HLD.
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...Juraj Vysvader
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I didn't get rich from it but it did have 63K downloads (powered possible tens of thousands of websites).
Prosigns: Transforming Business with Tailored Technology SolutionsProsigns
Unlocking Business Potential: Tailored Technology Solutions by Prosigns
Discover how Prosigns, a leading technology solutions provider, partners with businesses to drive innovation and success. Our presentation showcases our comprehensive range of services, including custom software development, web and mobile app development, AI & ML solutions, blockchain integration, DevOps services, and Microsoft Dynamics 365 support.
Custom Software Development: Prosigns specializes in creating bespoke software solutions that cater to your unique business needs. Our team of experts works closely with you to understand your requirements and deliver tailor-made software that enhances efficiency and drives growth.
Web and Mobile App Development: From responsive websites to intuitive mobile applications, Prosigns develops cutting-edge solutions that engage users and deliver seamless experiences across devices.
AI & ML Solutions: Harnessing the power of Artificial Intelligence and Machine Learning, Prosigns provides smart solutions that automate processes, provide valuable insights, and drive informed decision-making.
Blockchain Integration: Prosigns offers comprehensive blockchain solutions, including development, integration, and consulting services, enabling businesses to leverage blockchain technology for enhanced security, transparency, and efficiency.
DevOps Services: Prosigns' DevOps services streamline development and operations processes, ensuring faster and more reliable software delivery through automation and continuous integration.
Microsoft Dynamics 365 Support: Prosigns provides comprehensive support and maintenance services for Microsoft Dynamics 365, ensuring your system is always up-to-date, secure, and running smoothly.
Learn how our collaborative approach and dedication to excellence help businesses achieve their goals and stay ahead in today's digital landscape. From concept to deployment, Prosigns is your trusted partner for transforming ideas into reality and unlocking the full potential of your business.
Join us on a journey of innovation and growth. Let's partner for success with Prosigns.
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptxrickgrimesss22
Discover the essential features to incorporate in your Winzo clone app to boost business growth, enhance user engagement, and drive revenue. Learn how to create a compelling gaming experience that stands out in the competitive market.
Graspan: A Big Data System for Big Code AnalysisAftab Hussain
We built a disk-based parallel graph system, Graspan, that uses a novel edge-pair centric computation model to compute dynamic transitive closures on very large program graphs.
We implement context-sensitive pointer/alias and dataflow analyses on Graspan. An evaluation of these analyses on large codebases such as Linux shows that their Graspan implementations scale to millions of lines of code and are much simpler than their original implementations.
These analyses were used to augment the existing checkers; these augmented checkers found 132 new NULL pointer bugs and 1308 unnecessary NULL tests in Linux 4.4.0-rc5, PostgreSQL 8.3.9, and Apache httpd 2.2.18.
- Accepted in ASPLOS ‘17, Xi’an, China.
- Featured in the tutorial, Systemized Program Analyses: A Big Data Perspective on Static Analysis Scalability, ASPLOS ‘17.
- Invited for presentation at SoCal PLS ‘16.
- Invited for poster presentation at PLDI SRC ‘16.
Listen to the keynote address and hear about the latest developments from Rachana Ananthakrishnan and Ian Foster who review the updates to the Globus Platform and Service, and the relevance of Globus to the scientific community as an automation platform to accelerate scientific discovery.
Quarkus Hidden and Forbidden ExtensionsMax Andersen
Quarkus has a vast extension ecosystem and is known for its subsonic and subatomic feature set. Some of these features are not as well known, and some extensions are less talked about, but that does not make them less interesting - quite the opposite.
Come join this talk to see some tips and tricks for using Quarkus and some of the lesser known features, extensions and development techniques.
Developing Distributed High-performance Computing Capabilities of an Open Sci...Globus
COVID-19 had an unprecedented impact on scientific collaboration. The pandemic and its broad response from the scientific community has forged new relationships among public health practitioners, mathematical modelers, and scientific computing specialists, while revealing critical gaps in exploiting advanced computing systems to support urgent decision making. Informed by our team’s work in applying high-performance computing in support of public health decision makers during the COVID-19 pandemic, we present how Globus technologies are enabling the development of an open science platform for robust epidemic analysis, with the goal of collaborative, secure, distributed, on-demand, and fast time-to-solution analyses to support public health.
Globus Connect Server Deep Dive - GlobusWorld 2024Globus
We explore the Globus Connect Server (GCS) architecture and experiment with advanced configuration options and use cases. This content is targeted at system administrators who are familiar with GCS and currently operate—or are planning to operate—broader deployments at their institution.
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Shahin Sheidaei
Games are powerful teaching tools, fostering hands-on engagement and fun. But they require careful consideration to succeed. Join me to explore factors in running and selecting games, ensuring they serve as effective teaching tools. Learn to maintain focus on learning objectives while playing, and how to measure the ROI of gaming in education. Discover strategies for pitching gaming to leadership. This session offers insights, tips, and examples for coaches, team leads, and enterprise leaders seeking to teach from simple to complex concepts.
GraphSummit Paris - The art of the possible with Graph TechnologyNeo4j
Sudhir Hasbe, Chief Product Officer, Neo4j
Join us as we explore breakthrough innovations enabled by interconnected data and AI. Discover firsthand how organizations use relationships in data to uncover contextual insights and solve our most pressing challenges – from optimizing supply chains, detecting fraud, and improving customer experiences to accelerating drug discoveries.
3. Introduction Summary References
INTRODUCTION
We will examine how object-oriented programming
techniques can be applied to the problem of creating
container, or collection classes.
Containers in Dynamically Typed Languages.
The Tension between Reuse and Strong Typing.
Object Oriented Solutions.
Substitution and Downcasting.
Substitution and Overriding.
Templates.
Collection Traversals.
Iterators.
Visitors.
Container Classes Roaming Researchers, Inc. cbna
4. Introduction Summary References
CONTAINERS IN DYNAMICALLY TYPED LANGUAGES
Collection classes are simple to write in dynamically typed
languages, Since all variables are polymorphic.
Contains simply hold values in variables (which can hold
anything), and when they are removed from the container
they can be assigned to any variable.
Dynamically typed languages have historically come with a
rich set of container classes in their standard library.
Container Classes Roaming Researchers, Inc. cbna
5. Introduction Summary References
TENSION BETWEEN STRONG TYPING AND REUSE
The situation is very different when we move to statically
typed languages.
There, the strong typing can get in the way of software
reuse.
THE TENSION
lstsetlanguage=C++
type
Link = Record
value : integer
nextelement : ^ Link
end ;
What happens when we need a linked list of doubles? or of
a user defined type?
The strong typing is getting in the way of software reuse.
Container Classes Roaming Researchers, Inc. cbna
6. Introduction Summary References
CAN OO TECHNIQUES SOLVE THIS?
Can we bring any of the OO techniques (subsitution,
polymorphism) into the solution of this problem? We
examine three techniques:
Using Substitution and Downcasting.
Using Substitution and Overriding.
Using Templates (or Generics).
Container Classes Roaming Researchers, Inc. cbna
7. Introduction Summary References
USING SUBSTITUTION AND DOWNCASTING
In Java and other languages, (almost) all values can be
stored in a variable of type Object.
Therefore, we write containers that store Object values.
Problem. Requires a cast when a value is removed from
the container.
SUBSTITUTION
Vector aVector = new Vector ( ) ;
Cat Felice = new Cat ( ) ;
aVector . addElement ( Felice ) ;
. . .
/ / cast used to convert Object value to Cat
Cat animal = ( Cat ) aVector . elementAt ( 0 ) ;
Worse problem, typing errors are detected when a value is
removed from the collection, not when it is inserted.
Container Classes Roaming Researchers, Inc. cbna
8. Introduction Summary References
HETEROGENEOUS COLLECTIONS
Because any value can be stored in an Object, this allows
heterogeneous collections; although the actual type must
be checked when a value is removed:
EXAMPLE
Stack stk = new Stack ( ) ;
stk . addElement (new Cat ( ) ) ;
stk . addElement (new Dog ( ) ) ;
/ / . . . adding more values
/ / now do something with Cat values
i f ( stk . peek ( ) instanceof Cat ) {
/ / do conversion to Cat
Cat aCat = ( Cat ) stk . pop ( ) ;
/ / . . also do something with cat values
/ / now do something with Dog values
} else i f ( stk . peek ( ) instanceof Dog) {
/ / do conversion to Dog
Dog aDog = (Dog) stk . pop ( ) ;
/ / . . do something with Dog value
}
Container Classes Roaming Researchers, Inc. cbna
9. Introduction Summary References
USING CLASSES AS OBJECTS TO DO TYPE CHECKING
In languages in which classes are objects, and have the
ability to tell if an object is an instance, the container can
hold the class object that represents its type:
EXAMPLE
var
stack : TStack ;
aCat : TCat ;
aDog : TDog ;
begin
/ / create a stack that can hold only TCat values
stack := TStack . Create ( TCat ) ;
stack . push ( aCat ) ; / / ok
stack . push (aDog ) ; / / w i l l raise exception
. . .
end
Allows typing errors to be caught on insertion, but uses more
space and time.
Container Classes Roaming Researchers, Inc. cbna
10. Introduction Summary References
STRONG PRIMITIVE VALUES
In some languages (Java, Delphi) primitive types are not
objects.
These values cannot be stored using this scheme.
Thus, languages introduce wrapper classes that do
nothing but hold a primitive value.
EXAMPLE
Vector aVector = new Vector ( ) ;
aVector . add (new Integer ( 1 7 ) ) ; / / wrap up p r i m i t i v e i n t as Integer
. . .
Integer a = aVector . elementAt ( 1 ) ;
int x = a . intValue ( ) ; / / must subsequently be unwrapped
Container Classes Roaming Researchers, Inc. cbna
11. Introduction Summary References
USING SUBSTITUTION AND OVERRIDING
In certain situations we can eliminate the downcast,
replacing it with overriding.
This only works, however, if you can predict ahead of time
what operations you want to do on a collection.
Container Classes Roaming Researchers, Inc. cbna
12. Introduction Summary References
AN EXAMPLE, JAVA WINDOW EVENTS
A good example is the way that window events are handled
in Java.
Each window maintains a list of listeners, each listener
must implement a fixed interface (WindowListener).
EXAMPLE
public class CloseQuit extends WindowAdapter {
/ / execute when the user c l i c k s in the close box
public void windowClosing ( WindowEvent e ) {
System . e x i t ( 0 ) ; / / h a l t the program
}
}
When an event occurs the window simply runs down the list of
listener, invoking the appropriate method in each. No
downcasting required.
Container Classes Roaming Researchers, Inc. cbna
13. Introduction Summary References
A THIRD ALTERNATIVE – GENERICS
CODE
template <class T> class L i s t {
public :
void addElement (T newValue ) ;
T firstElement ( ) ;
private :
Link ∗ f i r s t L i n k ;
private class Link { / / nested class
public :
T value ;
Link ∗ nextLink ;
Link (T v , Link ∗ n ) : value ( v ) , nextLink ( n ) { }
} ;
} ;
Allow for both strong typing and reuse.
Container Classes Roaming Researchers, Inc. cbna
14. Introduction Summary References
COLLECTION TRAVERSAL
Here is another difficult problem.
How do you allow access to elements of a collection
without exposing the internal structure?
Consider the conventional solution:
EXAMPLE
var
aList : L i s t ; (∗ the l i s t being manipulated ∗)
p : Link ; (∗ a pointer for the loop ∗)
begin
. . .
p := aList . f i r s t L i n k ;
while ( p <> n i l ) do begin
w r i t e l n ( p . value ) ;
p := p ^ . nextElement ;
end ;
Needed to expose the link type, and the field nextElement.
Can we avoid this problem?
Container Classes Roaming Researchers, Inc. cbna
15. Introduction Summary References
There are two common solutions:
Create an iterator; an object that facilitates access to
elements and enumeration over the collection.
The vistor. Bundle the action to be performed as an object,
and pass it to the collection.
Container Classes Roaming Researchers, Inc. cbna
16. Introduction Summary References
ITERATOR
An iterator is an object that has two major responsibilities:
Provide access to the current element.
Provide a way to move to the next element.
Different languages use different interfaces, but the basic
idea is the same.
Container Classes Roaming Researchers, Inc. cbna
17. Introduction Summary References
AN ENUMERATION LOOP IN JAVA
EXAMPLE
/ / create the i t e r a t o r object
Enumeration e = aList . elements ( ) ;
/ / then do the loop
while ( e . hasMoreElements ( ) ) {
Object obj = e . nextElement ( ) ;
/ / . . . do something with obj
}
Interface consists of two methods, hasMoreElements and
nextElement.
Container Classes Roaming Researchers, Inc. cbna
18. Introduction Summary References
AN ITERATION LOOP IN C++
EXAMPLE
/ / create s t a r t i n g and stopping i t e r a t o r s
l i s t : : i t e r a t o r s t a r t = aList . begin ( ) ;
l i s t : : i t e r a t o r stop = aList . end ( ) ;
/ / then do the loop
for ( ; s t a r t != stop ; s t a r t ++ ) {
s t r i n g value = ∗ s t a r t ; / / get the value
/ / . . . do something with the value
}
Interface consists of three operations; comparison, increment,
and dereference.
Container Classes Roaming Researchers, Inc. cbna
19. Introduction Summary References
ITERATORS AND ENCAPSULATION
Note that the iterator must almost always have detailed
knowledge of the internal data structure.
Wasn’t our goal to hide these details?
Not exactly.
The iterator is usually developed by the same programmer
creating the data structure.
It can share detailed knowledge with the data structure.
And using the iterator does not require any knowledge of
how the iterator is implemented.
Often friends (in C++) or nested classes (in Java) can be
used to help the iterator share information with the
container.
Container Classes Roaming Researchers, Inc. cbna
20. Introduction Summary References
ALTERNATIVE, THE VISITOR
An alternative to iterators is the idea of a visitor.
Requires the ability to bundle the action to be performed
into an object, and hand it to the collection.
This is most common technique used in Smalltalk.
aList do: [:x | (’element is’ + x) print ].
The block is passed as argument to the list, which turns
around and executes the block on each element.
Container Classes Roaming Researchers, Inc. cbna
21. Introduction Summary References
THE VISITOR IN C++ IN THE STL
EXAMPLE
class printingObject {
public :
void operator ( ) ( int x )
{
cout << " value i s " << x << endl ;
}
} ;
printingObject p r i n t e r ; / / create an instance of the function object
for_each ( aList . begin ( ) , aList . end ( ) , p r i n t e r ) ;
The function for_each passes the object to element element in
the collection.
Container Classes Roaming Researchers, Inc. cbna
22. Introduction Summary References
SUMMARY
Collection Classes are easy to write in dynamically typed
languages.
In statically typed languages, there is a conflict between
reuse and strong typing.
Three approaches to overcoming this include.
Using substitution and downcasting.
Using substitution and overriding.
Using generics.
A related problem, looping over elements.
The iterator solution.
The visitor solution.
Container Classes Roaming Researchers, Inc. cbna
23. Introduction Summary References
REFERENCES
Images and content for developing these slides have been
taken from the follwoing book with the permission of the
author.
An Introduction to Object Oriented Programming, Timothy
Budd.
This presentation is developed with Beamer:
Szeged, dove.
Container Classes Roaming Researchers, Inc. cbna