Object Oriented Programming in primary education

advertisement
Object Oriented Programming in primary education
Irena Krajnović, senior student of class education
Ljubica Bakić-Tomić, Ph.D.
Vesna Markovac, engineer
The Faculty of Teacher Education of the University of Zagreb
Summary:
Informatics (computer science) as a subject in elementary schools is rather new. In
Croatia it is a faculty subject for children between 5th and 8th grade although there is a
tendency to introduce this subject in lower grades as well. Some elementary schools have
introduced informatics from the 1st grade so that the pupils would be as early as possible
introduced with media which surround them and that they learn how to use them in a correct
way. According to the official program computer science for elementary school pupils have
computer programming lessons as late as in 8th grade. Research studies in the world have
shown that computer programming is not conditioned with mathematical knowledge but
promotes development of procedural, algorithmic thinking and stimulates the spirit of
exploration. To achieve this, problems from others, already known fields of education, are
being used. Experience from USA indicate that children from the age of 7 years old should be
introduced in objective programming in a funny and acceptable way so that they learn to think
in procedures and algorithms.
On the foundation of education through games for development of procedural and
algorithmic way of thinking ability we can, from the 5th to the 8th grade, continue to build up
with real object oriented programming language.
This paper speculates on replacement of procedural programming languages (Pascal,
Basic and Logo) and traditional forms of education with object oriented programming
languages and modern approach to IT education. According to comparison of characteristics
of programming languages assistant tools we can choose corresponding technical
implementation in process of teaching. Elementary school educational applications have not
changed for several years. Therefore the potential of new technologies and adequate methods
has not been utilized. With this paper we suggest replacement of contemporary educational
program with new and more remunerative one.
Key words: programming, children, elementary school, computer science (informatics),
program, object-oriented approach, creativity, correlation, programming languages, C#,
Scratch, education.
2
Introduction
We have been inspired to write this paper by the whish to make programming in
schools more popular, to educate young people to be able to use this knowledge and to make
present curriculum more interesting and creative for the benefit of every pupil.
Programming is creative process which stimulates pupil. (Based on HNOS – Croatian
national education standard for elementary schools.) This should be achieved by connecting
other classes with the process of programming.
Contrary to the general conviction, computer programming is not conditioned by
mathematical knowledge but promotes development of procedural, algorithmic thinking and
stimulates the spirit of exploration. To achieve this, problems from others already known
fields of education are being used.
Object oriented programming in easier and in a more simple way achieves the goal –
determined definition of programming – in a way that the creativity of pupils from various
fields (classes) can be used in a better way. Also there is an opportunity for betterment of
communication (better cooperation between pupils) on multidisciplinary problems by using
natural interest for specified class (field) of every pupil.
Discussion
Historic retrospective on the creation of program languages - Current situation
Problem connected with present day education program in informatics (computer
science) is seen at the beginning of creation of programm languages. It shows that the present
school curriculum is outdated. For instance Logo was created in 1967, then Pascal in 1970.
(These programming languages are presently being lectured in Croatian schools.) Era of
procedural programming for programmers stops with the creation of C++ in 1985, and the
development goes to object-oriented programming. In 1995 new programming language Java
emerged, and then in the year 2001. C# was developed.
The difference between procedural and object-oriented programming
Object-oriented programming (OOP) is a programming language model organized
around "objects" rather than "actions" and data rather than logic. The first step in OOP is to
identify all the objects you want to manipulate and how they relate to each other, an exercise
often known as data modeling. Once you have identified an object, you generalize it as a class
of objects (think of Plato's concept of the "ideal" chair that stands for all chairs) and define the
kind of data it contains and any logic sequences that can manipulate it. Each distinct logic
sequence is known as a method. A real instance of a class is called an "object" or an "instance
of a class." The object or class instance is what you run in the computer. Its methods provide
computer instructions and the class object characteristics (properties) provide relevant data.
You communicate with objects - and they communicate with each other - with well-defined
interfaces called messages.
Some important features of object-oriented programming are as follows:
o
Emphasis on data rather than procedure
3
o
o
o
o
o
Programs are divided into Objects
Data is hidden and cannot be accessed by external functions
Objects can communicate with each other through functions
New data and functions can be easily added whenever necessary
Follows bottom-up approach
Object-Oriented Programming has the following advantages over conventional approaches:
o
o
o
OOP provides a clear modular structure for programs, which makes it good for
defining abstract data types where implementation details are hidden and the unit has a
clearly defined interface.
OOP makes it easy to maintain and modify existing code as new objects can be
created with small differences to existing ones.
OOP provides a good framework for code libraries where supplied software
components can be easily adapted and modified by the programmer. This is
particularly useful for developing graphical user interfaces.
The focus of procedural programming is to break down a programming task into a
collection of data structures and subroutines, whereas in object oriented programming it is to
break down a programming task into objects. Either method can be valid for accomplishing a
specific programming task. (Object orientation is often referred to as OO and object oriented
programming as OOP.)
The most popular programming languages usually have both OOP and procedural aspects.
Some differences (Table 1) between pure object-oriented languages and non-OO procedural
languages:
Object Oriented Procedural
methods
functions
objects
modules
message
call
member
variable
Table 1.: differences between object-oriented languages and procedural languages
The advantages of object-oriented programming are more efficient graphic interface
and web development, where one could recognize inspiration with object-oriented
programming in implementation of XML and HTML program languages. They write
(serialize) objects and through them define how the objects will be instanced.
Procedural programming is used on lower levels of operating system (OS) (kernel,
drivers, modules), and higher levels of OS and additional applications (tools) are here to give
us advantages of object programming. If OS gives us this opportunity, why not use it?
Appearance of complex object code, compared to procedural code, is much easier to
read and memorize and it is easy to be inherited – i.e. to create class inside class. Also, objectoriented programming easily discerns between data and program procedures.
Because OOP uses polymorphism it is easier to use the same functions/methods in
different environments. Two classes that inherit one base class can have a method which both
subclasses override in their own way. For example, if we have a base class Animal with
method speak(), and two subclasses Dog and Pig which override it with bark() and oink()
representatively, when we call an object instance method speak(), it will call the method
bark() if the object is a dog, and method oink() if the object is a pig. This will happen without
4
using any conditional functions as we would have to do in procedural programming
languages. This is very useful if we are working within complex systems and in multideveloper environments.
Difference between other approaches which focus on actions which are being
performed on data structures, and this approach is in focus on building application as group of
objects which exchange messages.
We understand the world as a group of objects, and not through procedures; therefore
objects comprehend procedures and properties also. It is easier for children to understand a
real example which happens to them everyday. For instance, we can tell to a child to sit down
(command). During the process of sitting down a child will not think of moving the chair,
bending and all other procedures in to-sit-down process. It will comply with one simple
command. The same example can be used to explain to the children how the object
programming looks like.
Programmer methods of procedural programming will not be completely omitted with
transition to object programming. They are used inside the method of class to execute
procedural tasks over objects or their properties. Children would continue to study basic
conditions, logic comparison, loops etc.
Programming languages
Most of the PC's in Croatia use Windows XP 1 OS, therefore, up to date PC's are being
used. It is easier to start C# applications on these PC's because they are equal to any Windows
application. Applications developed in C# demand only .Net framework which comes as a
supplement when updating Windows or it is distributed together with the application.
C# is an Object Oriented Programming language and has at its core many similarities
to Java, C++ and VB. In fact, C# combines the power and efficiency of C++, the simple and
clean object oriented design of Java and the language simplification of Visual Basic.
Like Java, C# also does not allow multiple inheritance or the use of pointers (in
safe/managed code), but does provide garbage memory collection at runtime, type and
memory access checking. However, contrary to Java, C# maintains the unique useful
operation of C++ like operator overloading, enumerators, pre-processor directives, pointers
(in unmanaged/unsafe code), function pointers (in the form of delegates) and supports the
concepts of properties.
Big advantage among most of recent programming languages is that programs are
written in Java and can perform tasks without changes on any OS for which JVM (Java
Virtual Machine) already exists.
Development environment exists in free versions for both (Visual studio C# Express,
Eclipse for Java and other).
C# offers attractive and popular possibilities such as for instance development of
games (XNA – also exists express version similar to Visual studio which is intended for
nonprofessional development of games) for X-box (popular gaming console which competes
with PS2) or robotics control (Robotics studio) for which we need a good grip on physics and
technology. Such created programs could be used in their education. For instance, multi-user
foreign language PC dictionary application with already known words, could be made. With
further development this project could grow into a web database or application for easy
1
http://www.w3schools.com/browsers/browsers_os.asp
5
translation. Many other similar examples already exist which can catch children’s' attention
and stimulate them to develop their skills and explore other subjects.
Detailed resolution between adequate object-oriented programming languages must be
left to experts from IT and educational sciences.
Application in elementary school
We believe that pupils in elementary school should study computer science from 1st or
2nd grade.
Reasons for that are, first, to develop abstract-thinking skills from the concrete to the
general. If we would ask children to solve one problem, they would have one answer, but if
we tell them to provide a method for solving all problems like this one, children would make
an algorithm for solving problems.
Second, developing systematic ways of thinking about process (describing processes
precisely and abstractly, reasoning about the correctness of processes, analyzing the efficiency
of processes), data and relationships (types: hierarchies, containment, composition; structures:
arrays, trees, directed graphs, mappings; patterns: delegation, data flow, publish/subscribe)
and the ability to create custom software which provides a practical advantage in almost every
field.
Thirdly, research shows that students make career choices as early as 8th grade. If a
student has no exposure to a discipline, they are unlikely to think about it as a career. Also,
underrepresented groups, particularly women, may enjoy computer science but need
encouragement. Student experience is needed to counteract media portrayal of computing
professionals. Moreover, our country needs more computer scientists.
Not everyone becomes a physicist or biologist, but we teach these subjects in
elementary school so people have a basic understanding of the world around them. Citizens
and elected officials with even a limited understanding will make better decisions about the
use of technology. Demystification is an important goal for education.
Fact is that software is everywhere. If students do not learn computer science in
elementary school, they will live their lives surrounded by technology that they do not
understand.
Learning and playing
Creation of a computer game may demand several disciplines like:
 linguistic subjects (talk between characters, theme, novel, story, communication in various
languages)
 visual arts (drawing, animation)
 musical arts (creation of sound and music)
 physics (interaction of characters, mechanics)
 physical education (sports rules)
 history, geography, chemistry and biology (facts from real life).
Pupils through exploring various disciplines expand their knowledge about that subject
and get insight of the way the discipline works through logical and objective thinking about
the discipline.
Linguists will have better understanding of functioning of spoken language and in this
way a predisposition for easier learning of program language. Better knowledge of literature
6
will make better themes for program. Visual artists get new dimension of animated characters,
musicians create music for the course of the story, and in cooperation they can connect speech
and intonation with the characters. Pupils interested in history can get in the realistic situation
of the age they are interested in and for which they are creating the game in a way that they
must get all the facts of that period (for instance – was there electricity in the 17th century?)
and in this way they can understand passed times better. Geographers will have to learn facts
to be able to study a terrain, climate or soil composition. Chemistry and biology will give
more means to explain complex things like chemical reactions or birds flying by using 3D
animation.
In our attempt to introduce basics of programming to children we know that it is very
important for expression and creation in a world of computers to teach them the code in a
creative way. In the Prix Ars Electronica festival2 competition children from the age group of
8 compete in creating programs/media thus showing that they are not just consumers but
creators as well.
Program Scratch
In developed countries basics of programming are being tough in elementary schools
from the age of 8 years. This IT learning will be useful to them in their future education. In
some schools teaching is done through Scratch application („EXPO Elementary School in St.
Paul“).
2
http://www.aec.at/en/prix/index.asp
7
Picture 1.: Scratch - application interface
Scratch was developed by MIT (Massachusetts institute of technology) from which
Logo originates. It is intended for children from 8 to 16 years of age, but younger children can
use it also. By using this program, children acquire knowledge which will help them in
creative thinking, systematic analysis, use of technology, efficient cooperation and permanent
learning. This programm we would intend for children from 2nd to 4th grade of informatics
(computer science) to acquire relevant base knowledge of object in funny and particular way.
This new tools (and associated activities) can be used successfully and productively because:
• youth sees the tool/activities as “cool,” resonating with their interests and passions
• youth sees the value and potential of the tool right away
• youth can create a first project with the tool quickly and easily
• youth can create “products” that they can show off to others (pride of authorship)
• the tool supports a wide range of different types of activities
• the tool/activities appeal to youth of different backgrounds and cultures
• youth can learn features of the tool gradually and incrementally
• youth can continue to use the tool in ever more complex ways over time
Programming in Scratch is based on putting together blocks in which pupil puts
together procedures to graphically connect depicted blocks (just like LEGO Bricks). When
kids use programmable LEGO Bricks, for instance, they can create anything from a robotic
creature, a “smart” house, an interactive sculpture to a musical instrument.
Picture 2.: Snapping graphical blocks together
Different types of data are shown in various forms of blocks where parts fit in a way
that they connect together in a correct syntactic order. In the second picture the program is
shown which will be executed in a way to make the chosen character in the game make 150
steps. After it moves for that value in two seconds it will say „Good day to you!“ and will
play a sound No. 58 for half a second.
8
Picture 3.: Programm in execution
This approach blocks syntax mistakes and makes children focus their attention on the
problem they want to solve, and not on the mechanic of programming itself.
The most popular projects will contain manipulation of images, video, and music.
Youth will be able to share objects at all levels (from procedure blocks to animated characters
to full projects) and to exchange them between all types of devices (desktops, laptops, tablets,
handhelds, mobile phones, embedded devices). Through these activities, it is expected that an
ecosystem of Scratch creations will develop, with youth constantly trading and modifying one
another’s creations.
9
Programming for life
We will explain exactly what is considered by object-oriented programming, through
programmer’s eyes, in a way in which children from 5th to 8th grade will understand.
The world around us can be divided up into different classes of things such as “cats”
or “houses” or “trees”. These classes can be thought of as categories or labels for grouping
similar things. We need a way to describe these classes to the computer so it can solve
problems about them.
In each class of things are some specific objects that we are interested in. For example,
within the class “cat” is my cat Fluffy who is an object of the cat class. Similarly, the pink
house on the corner of my street is an object of the “house” class and the oak tree outside my
bedroom window is an object of the “tree” class. When there is a specific object we want the
computer to work with, we must write some description down for the computer that
represents that object.
Objects have a variety of properties. Properties are the things that describe the objects
more clearly. If you remember your English classes, properties are like adjectives in the
English language. For example, my cat Fluffy may be described with properties such as
height, weight, etc.
Events are things that happen to an object. In the real world, events occur around us all
the time. For example, when I pet my cat Fluffy, it is an event that happens to Fluffy.
Similarly, the wind blowing through the branches of the oak tree outside my window is an
event that happens to the tree. Events are usually actions that affect the specific object, but
which the object has no control over. In the computer's world, the events are usually things
like "a button was clicked" or "the mouse was moved".
Actions are things that an object does. For example, my cat Fluffy licks its fur – that is
an action. In the computer’s world, sometimes when certain interesting events occur, we want
to fire off certain actions, like "when this button is clicked, draw me a picture of a cat".
Computers, unbelievably, are really dumb. A computer has no idea how to draw a cat.
So we have to write down, in a way the computer can understand, the method for drawing a
cat. This is a set of step-by-step instructions that tells the computer how to do it, like a recipe.
In C#, we describe a class to the computer like this:
class Animal
{
}
From just this little bit of code it now knows:



we want to talk about a class of things
we will be calling that class Animal
everything we tell it about this class will be written between the curly braces { … }.
10
Animal fiddleSticks;
The computer understands this to mean “This human wants to talk about something in the
Animal class and wants to call it "fiddleSticks".
fiddleSticks = new Animal();
This is called "instantiating the object". In this example, " fiddleSticks" is now an
instance of "Animal". Another way to say this is fiddleSticks is an "object" of type "Animal".
Either way, we know clearly that we are talking about a specific Animal now.
Next, we have to add some fields to our class definition:
class Animal
{
string kindOfAnimal;
string name;
int numberOfLegs;
int height;
int length;
string color;
bool hasTail;
bool isMammal;
bool spellingCorrect;
}
We have explained to the computer that ALL Animals have these fields. Now, let’s
ask it to create an instance representing a specific one of these animals and then let us tell the
computer some things about that specific animal - by giving values for each field.
Animal fiddlesticks;
fiddlesticks = new Animal();
fiddlesticks.kindOfAnimal = "Cat";
fiddlesticks.name = "Fiddlesticks The Cat";
fiddlesticks.numberOfLegs = 4;
fiddlesticks.height = 50;
fiddlesticks.length = 80;
fiddlesticks.color = "Black";
fiddlesticks.hasTail = true;
fiddlesticks.isMammal = true;
In C#, a method is a piece of code that describes to the computer the way that it should
do something. When we later call that method, the computer runs through the code, doing
exactly what we wrote.
11
void SayHello()
{
Console.WriteLine("Hello");
}
If we were to call this method now, it would write the word “Hello” into the screen.
By writing down the code above, we have taught the computer HOW to write hello to the
screen, but we have not yet told it to actually do this.
SayHello();
What we have mentioned before is just an example of using basics of C# programming
language. Of course, C# is much more complex and has much more possibilities than what is
shown here.
The development surroundings of Visual Studio 2005 is shown in the picture bellow.
Programm code simulate an example shown before in Scratch (picture no.2). Code depicts
class Human which inherits Character and two new methods. In the example of the first
method (do-while) endless loop is being used. This loop is often used in procedural
programming. The MyAction method is similar in functions to procedural programming and
the difference is that we had to call it with the prefix „this.“ so that we could order it to be
used inside present class.
Picture 4.: Visual Studio - programm interface
12
Picture 5.: Java - programm interface
Application on the internet
By classes already implemented in the .Net Framework, pupil can make their own
dynamic web applications. This gives their programming work „international life“ plus
interaction with other pupil work. Web applications can have much larger public than usual
PC applications. Web tools like forum, blog, social network webpage and system for content
management give the children opportunity to realize earlier the advantages of Internet for
spreading and alleviation of communication with other pupil and schools.
Modern programming languages and their developing surroundings support group
work of more computer programmers. Pupils can cooperate on team projects through servers
for code publishing. This technology connects pupils from various classrooms and schools so
that they could cooperate on unique projects independently from time and space in which the
programming takes place. Also, homework from computer science can be made easier if pupil
have access to server via internet.
Communication with pupils who need extra explanation or those who missed some
lecture could be made easier through online multimedia presentation of the subject. Using
tools like Adobe Captivate, Techmsith Camtasia Studio or some free screen-capture, teachers
could save all their lectures with demonstrations, slides and soundtracks included. Publishing
of presentations could be integrated with the rest of the web application.
13
Conclusion
Through this simple procedures and introduction of new technologies a wide potential
for development of whole information society is being opened. Pupils in elementary school
will get a better idea on how programming looks like in reality and higher educational
institutions will get more focused and experienced students. If in the equation we put
enormous potential of the Internet - net of all resources – time and place will no longer be a
problem not even for the most far away islands as it is not for the centers of the big cities.
14
Literature
http://hr.wikipedia.org/wiki/Objektno_orijentirano_programiranje
http://en.wikipedia.org/wiki/Object-oriented_programming
http://hr.wikipedia.org/wiki/Java_%28programski_jezik%29
http://msdn2.microsoft.com/en-us/library/bb330920(VS.80).aspx
http://scratch.mit.edu/
http://scratch.mit.edu/pages/research
http://searchdatamanagement.techtarget.com/sDefinition/0,,sid91_gci211902,00.html
http://www.bestsoftware4download.com/download/t-free-c-school-ebook-downloadllijghlw.html
http://www.eclipse.org/
http://www.startvbdotnet.com/oop/default.aspx
http://msdn2.microsoft.com/en
http://llk.media.mit.edu/projects/scratch/papers/Scratch-21stCenturySkills.pdf
http://en.wikipedia.org/wiki/Comparison_of_C_Sharp_and_Java
http://public.mzos.hr/Default.aspx?sec=2225
http://en.wikipedia.org/wiki/C_sharp
15.08.2007.
16.08.2007.
15.08.2007.
30.04.2007.
20.08.2007.
20.08.2007.
16.08.2007.
17.08.2007.
16.08.2007.
17.08.2007.
21.06.2007.
15.07.2007.
28.06.2007.
28.08.2007.
12.08.2007.
Kiš Miroslav; (2000.) Englesko-hrvatski i hrvatsko-engleski informatički rječnik, 1. izd. –
Naklada Ljevak, Zagreb
Mayo Joseph (prijevod s engleskog Zoran Juras); (2002.) C# programski jezik, Miš, Zagreb
Peppler, K. i Kafai, Y. (2005). Creative coding: The role of art and programming in the K-12
educational context
15
Download