Title: Java for ColdFusion Programmers
1Java for ColdFusion Programmers
2What we'll cover
- Why OO?
- What is OO?
- Why Java?
3Theory of Constraints
- According to the Theory of Constraints, any
system has only one current constraint that
hinders the system from producing - Working on anything other than that is
misdirected effort and can actually be worse than
doing nothing
4What's so great about OO?
- The greatest threat to softwareto both
successful deployment and maintenanceis
complexity - Object orientation offers us the best tools yet
devised for managing that complexity
5Food for thought
- "Any intelligent fool can make things bigger and
more complex. It takes a touch of geniusand a
lot of courageto move in the opposite
direction." - -Einstein
6What tools are available in OO for managing
complexity?
- Encapsulation
- Polymorphism
- Inheritance
7Fabulous prizes time
- List as many data types as you can
8About data types
- The primary goal of a type system is to ensure
language safety by ruling out all untrapped
errors in all program runs. The declared goal
of a type system is usually to ensure good
behavior of all programs, by distinguishing
between well typed and ill typed
programs. Cardelli
9What is object orientation?
- Object orientation (OO) is a way of constructing
software such that an simplified, idealized model
of the world under consideration is created in
software components that encapsulate the
statefulness and behavior of the inventory of the
world and that may change their state or perform
some behavior in response to a message sent to
them
10What did he just say?
- "simplified, idealized model of the world under
consideration is created in software components
that encapsulate the statefulness and behavior "
PackageDeliverer
route Route assignedTruck Truck hourlyPayrate
numeric hoursWorked numeric
deliverPackages()boolean collectCOD()
void completeTimecard() void getPayDue() numeric
11What did he just say?
- that may change their state or perform some
behavior in response to a message sent to them
doC()
doB()
route assignedTruck hourlyPayrate hoursWorked
obj.getRoute()
getRoute()
doD()
obj.hoursWorked
doH()
doE()
doG()
doF()
12Breathing life into models
- Defining classes is done at design time
- At run time, classes are instantiated, producing
objects - An OO application is nothing but a number of
objects sending messages back and forth to on
another
13What's so great about Java?
- The power of Java lies in object orientation
- For most procedural programmers, OO takes time to
penetrate - When learning OO, it's very important to lay good
foundations - Java is simply a very good implementation of
object orientation
14Java Encapsulation
- Data and behavior in a single software component
the class - A class is like a blueprint or cookie cutter from
which objects are created
Class
Objects
15Encapsulation
- Encapsulation allows the details of a component
to be hidden from users of the component. In
place of exposing its internals, a
well-encapsulated component exposes an interface
or specification.
16A specification
- The Cat class has, as part of its specification,
a play() method. When called, each Cat object
will carry out its play method. We know only what
it will do, not how it will do it.
I can play()
17Encapsulation in Java
- Let's build a simple class, Cat
- The Cat class will have
- properties
- name
- color
- methods
- get/setName()
- get/setColor()
- play()
- Remember that Cat is a blueprint. To create an
actual Cat object, we'll use CatDemo.java
18Polymorphism
- Polymorphism allows different objects to be
treated as having the same specification and/or
one object to be treated as belonging to
different specifications
19Treating different objects as having the same
specification
- Java allows different objects to assume the same
type - Java allows the same object to assume different
types
20Polymorphism in Java
- Let's build a simple class, RobotDog
- The RobotDog class will have
- properties
- voltage
- batteryLife
- methods
- get/setVoltage()
- get/setBatteryLife()
- play()
21Interface
- A specification without implementation
- Acts as a data type
- An interface is like a role that an object can
step into - The object, joe, might be "born" as a Welder, but
may also implement - Father
- Son
- Voter
- PokerPlayer
22Inheritance
- A special case of polymorphism in which one class
is a specialized type of another class - HourlyEmployee Employee
- SportsCar Car
- TypicalManager CluelessDolt
- When one class inherits from another, it inherits
all those properties and methods not declared to
be private
23Why is OO a big deal?
- If you're a programmer, you must know OO
- OO gives you, the programmer, better tools for
dealing with - changing requirements on current projects
- maintaining existing code
- team development
24But why Java?
- So that you'll learn OO right
- Once you learn OO, you can then use
- CFCs
- C.NET
- Visual Basic.NET
- Ruby
- Eiffel
- etc.
25Food for thought
- "Students usually demand to be taught the
language that they are most likely to use in the
world outside. This is a mistake. A well taught
student can easily pick up the languages of the
world, and will be in a far better position to
recognize their bad features as they encounter
them." - C. H. Lindsey
26To learn more
- Books
- Head First Java published by O'Reilly
- Java for ColdFusion Developers by Eben Hewitt
- Training/Mentoring
- Java for ColdFusion Programmers (halhelms.com)