SlideShare une entreprise Scribd logo
1  sur  26
Télécharger pour lire hors ligne
All the Java ADF Beginners
       need to know! – Part 2

           Markus Eisele
           Oracle ACE Director
           msg systems ag, Germany



1              Markus Eisele         msg systems ag, JUNE 26 - 2011
http://blog.eisele.net
http://twitter.com/myfear
markus@eisele.net
Overview



         1.    Introduction
         2.    Basic Object Oriented Concepts
         3.    Classes and Objects
         4.    Exceptions
         5.    Generics
         6.    Design Pattern




3                                           Markus Eisele   msg systems ag, JUNE 26 - 2011
Introduction



         •   YOU„VE MISSED (or skipped) part 1 ;) (The real
             basics)
         •   Let„s get more theoretical and detailed now!

         •   Disclaimer:
             Even if there is “ADF” in the title, we still don’t
             touch ADF or even open up JDeveloper …




4                                            Markus Eisele         msg systems ag, JUNE 26 - 2011
Why do you have „ADF“ in the title?




5                                         Markus Eisele   msg systems ag, JUNE 26 - 2011
What is Object Orientation?


         Procedural paradigm:
          • Software is organized around the notion of procedures
          • Procedural abstraction
              Works as long as the data is simple
          • Adding data abstractions
              Groups together the pieces of data that describe some
                entity
              Helps reduce the system‟s complexity.
                   - Such as Records and structures

         Object oriented paradigm:
          • Organizing procedural abstractions in the context of data
            abstractions




6                                      Markus Eisele           msg systems ag, JUNE 26 - 2011
Object Orientation paradigm


         An approach to the solution of problems in which all
         computations are performed in the context of objects.

           • The objects are instances of classes, which:
               are data abstractions
               contain procedural abstractions that operation on the
                objects

           • A running program can be seen as a collection of objects
             collaborating to perform a given task




7                                     Markus Eisele               msg systems ag, JUNE 26 - 2011
Concepts that Define Object Orientation



         Necessary for a system or language to be object oriented (OO)
         • Identity
                 Each object is distinct from each other object, and can be referred to
                 Two objects are distinct even if they have the same data
         •   Classes
                 The code is organized using classes, each of which describes a set of
                  objects
         •   Inheritance
                 The mechanism where features in a hierarchy inherit from superclasses to
                  subclasses
         •   Polymorphism
                 The mechanism by which several methods can have the same name and
                  implement the same abstract operation.




8                                     Markus Eisele, Oracle ACE Director FMW & SOA         msg systems ag, JUNE 26 - 2011
Other Concepts



         •   Abstraction
                 Object -> something in the world
                 Class -> objects
                 Superclass -> subclasses
                 Operation -> methods
                 Attributes and associations -> instance variables
         •   Modularity
                 Code can be constructed entirely of classes
         •   Encapsulation
                 Details can be hidden in classes
                 This gives rise to information hiding:
                     Programmers do not need to know all the details of a class




9                                       Markus Eisele, Oracle ACE Director FMW & SOA   msg systems ag, JUNE 26 - 2011
Classes and Objects



          •   Object
                  A chunk of structured data
                  Has properties (attributes)
                       Representing it„s state
                  Has behaviour (methods)
                       Representing how it acts and reacts
                       Simulates the behaviour of the object in the real worl




          •   Class
                  Is a unit of abstraction
                  It„s instances represent similar objects
                  Is a kind of software module
                  Has methods
                       to implement behaviour




10                                                      Markus Eisele            msg systems ag, JUNE 26 - 2011
Class or Instance?



          •   Something should be a class if it could have
              instances
          •   Something should be an instance if it is clearly a
              single member of a set defined by a class

          •   Person
                  Class: instances are individual persons
          •   Markus
                  Instance: A person with the name: „Markus“
          •   …

          •   The act of creating an object instance of a class is
              called the instantiation of the class.

           Person markus = new Person(„Markus“);




11                                                Markus Eisele      msg systems ag, JUNE 26 - 2011
Name your Classes



          •   Use capital letters
                  Classes always start with capital letters
                  E.g. CellPhone NOT cellPhone


          •   Use singular nouns
                  A class is a generalization of a single object.
                  E.g. Person NOT Persons


          •   Use the right level of generality
                  This highly depends on souroundings. Be as specific as
                   needed.
                  E.g. Cat not Animal


          •   Make sure the name has only one meaning




12                                                  Markus Eisele           msg systems ag, JUNE 26 - 2011
Encapsulation and Class attributes and methods

          •   Attributes and methods have visibility modifier

                  private
                   Visible to all class internal methods and attributes.
                   private List<Person> attendees;

                  protected
                   Visible to all the classes within the same package and to sub-classes.
                   protected List<Person> getAttendees();

                  public
                   Visible outside the class. Public interface to access and manipulate
                   objects
                   public Date fromDate;

                  No modifier / package-private
                   Visible outside the class. Public interface to access and manipulate
                   objects

          •   Class attributes and methods are marked with the keyword
              „static“. Can be combined with any of the above visibility modifier.

                  protected static int MAX_ATTENDEES;




13                                                       Markus Eisele                      msg systems ag, JUNE 26 - 2011
Inheritance



          •   Classes can be organized into a hierarchical
              inheritance structure, where a child class inherits
              attributes from a parent class. Also known
              synonymously as an inheritance tree.
          •   A child class is synonymous with the term subclass
              or derived class. The parent class is synonymous
              with the terms superclass or base class.
          •   The inheritance tree may run many levels deep.
          •   In a pure Object-Oriented system, a class may
              support multiple inheritance.

          public class Student extends Person {
          }

          •   Always check generalizations to ensure they obey
              the “is a” rule:
                  “A Student is a Person”
                  “A village is a municipality”



14                                                 Markus Eisele    msg systems ag, JUNE 26 - 2011
Abstract classes and methods

          •   An operation should be declared to exist at the
              highest class in the hierarchy where it makes sense
                  The operation may be abstract (lacking implementation)
                   at that level
                  If so, the class also must be abstract
                      No instances can be created
                      The opposite of an abstract class is a concrete class
          •   If a superclass has an abstract operation then its
              subclasses at some level must have a concrete
              method for the operation
                  Leaf classes must have or inherit concrete methods for
                   all operations
                  Leaf classes must be concrete

          public abstract class Person {
              public abstract String drinkingHabits();
          }

          public class Student extends Person {
              public String drinkingHabits() {
                  return "Lot of beer!";
              }
          }




15                                                    Markus Eisele            msg systems ag, JUNE 26 - 2011
Polymorphism


         •   One object calls another through a message,
             specifying a called method. If that method is found
             within the receiver class, the method is invoked. If
             the method is not found the receiver class‟s parent
             class equivalent method is invoked, and so on. This
             behavior is called polymorphism
         •   Polymorphism extends not only to the methods but
             also the attributes of an object.


             public class Person {
                 private String name;
                 private String surename;

                 public Person(String name, String surename) {
                     this.name = name;
                     this.surename = surename;
                 }
             }

             public class Student extends Person {
                 public Student(String name, String surename) {
                     super(name,surename);
                 }
             }



16                                            Markus Eisele         msg systems ag, JUNE 26 - 2011
Interfaces



          •   Like abstract classes, but cannot have
              executable statements
                Define a set of operations that make sense in
                  several classes
                Abstract Data Types
          •   A class can implement any number of interfaces
                It must have concrete methods for the
                  operations


                  public interface Mammal {
                      public abstract List<Mammal> getChildren();
                  }

                  public abstract class Person implements Mammal {

                      public List<Mammal> getChildren() {
                          return Collections.emptyList();
                      }
                  }




17                                                 Markus Eisele     msg systems ag, JUNE 26 - 2011
Exceptions



          •   Anything that can go wrong should result in the
              raising of an Exception. Exception is a class with
              many subclasses for specific things that can go
              wrong.
          •   Use a try - catch block to trap an exception

              try
              {
                 int x = 1/0;
              }
              catch (ArithmeticException e)
              {
                // code to handle division by zero
              }




18                                             Markus Eisele       msg systems ag, JUNE 26 - 2011
Generics



          •     J2SE 5.0 and higher provides compile-time type safety with the Java
                Collections framework through generics
          •     Generics allows you to specify, at compile-time, the types of objects you
                want to store in a Collection. Then when you add and get items from the
                list, the list already knows what types of objects are supposed to be acted
                on.
          •     So you don't need to cast anything. The "<>" characters are used to
                designate what type is to be stored. If the wrong type of data is provided, a
                compile-time exception is thrown.

                Sample<String> object = new Sample<String>();

                public class Sample<T> {
                    private T data;

                    public void setData(T newData) {
                        data = newData;
                    }

                    public T getData() {
                        return data;
                    }
                }




19                                                 Markus Eisele                         msg systems ag, JUNE 26 - 2011
Design Pattern




          • The recurring aspects of designs are called design
            patterns.
              A pattern is the outline of a reusable solution to a
                general problem encountered in a particular context
              Many of them have been systematically
                documented for all software developers to use
              A good pattern should
                  Be as general as possible
                  Contain a solution that has been proven to
                   effectively solve the problem in the indicated
                   context.
             Studying patterns is an effective way to learn from the
                experience of others


20                                    Markus Eisele              msg systems ag, JUNE 26 - 2011
Description of Pattern



               Context:
                   • The general situation in which the pattern applies
               Problem:
                    A short sentence or two raising the main difficulty.
               Forces:
                   • The issues or concerns to consider when solving
                     the problem
               Solution:
                   • The recommended way to solve the problem in the
                     given context.
                         —„to balance the forces‟
               Antipatterns: (Optional)
                   • Solutions that are inferior or do not work in this
                     context.
               Related patterns: (Optional)
                   • Patterns that are similar to this pattern.
               References:
                   • Who developed or inspired the pattern.


21                                Markus Eisele, Oracle ACE Director FMW & SOA   msg systems ag, JUNE 26 - 2011
Example Singleton Design pattern



          •   Singletons can be used to create for example Connection Pool. If
              programmers create a new connection object in every class that
              requires it, then its clear waste of resources. In this scenario by using
              a singleton connection class we can maintain a single connection
              object which can be used throughout the application.




22                                   Markus Eisele, Oracle ACE Director FMW & SOA   msg systems ag, JUNE 26 - 2011
Gang of Four (GoF) Pattern




                                                                                 Design Patterns, Elements of Reusable
                                                                                 Object-Oriented Software - Erich
                                                                                 Gamma, Richard Helm, Ralph Johnson,
                                                                                 John M.
                                                                                 ISBN: 978-0-2016-3361-0
                                                                                 http://bit.ly/iojEpw

23                                Markus Eisele, Oracle ACE Director FMW & SOA                   msg systems ag, JUNE 26 - 2011
Lesson in a tweet




      “Good programmers use their brains,
      but good guidelines save us having
      to think out every case.”
      (Francis Glassborow)




      http://www.devtopics.com/101-great-computer-programming-quotes/


24                                             Markus Eisele, Oracle ACE Director FMW & SOA   msg systems ag, 26/06/11
Thanks!




               http://www.sagecomputing.com.au/



25                      Markus Eisele, Oracle ACE Director FMW & SOA   msg systems ag, 26/06/11
Thank you for your attention




     Markus Eisele

     Principle IT Architect

     http://blog.eisele.net
     http://twitter.com/myfear

     www.msg-systems.com




                                 www.msg-systems.com




26                                    Markus Eisele    msg systems ag, JUNE 26 - 2011

Contenu connexe

Similaire à All the Java ADF beginners need to know - part2

The View object orientated programming in Lotuscript
The View object orientated programming in LotuscriptThe View object orientated programming in Lotuscript
The View object orientated programming in Lotuscript
Bill Buchan
 
L ab # 07
L ab # 07L ab # 07
L ab # 07
Mr SMAK
 

Similaire à All the Java ADF beginners need to know - part2 (20)

Introduction to OOP with java
Introduction to OOP with javaIntroduction to OOP with java
Introduction to OOP with java
 
Oops concepts
Oops conceptsOops concepts
Oops concepts
 
Abap object-oriented-programming-tutorials
Abap object-oriented-programming-tutorialsAbap object-oriented-programming-tutorials
Abap object-oriented-programming-tutorials
 
The View object orientated programming in Lotuscript
The View object orientated programming in LotuscriptThe View object orientated programming in Lotuscript
The View object orientated programming in Lotuscript
 
Review oop and ood
Review oop and oodReview oop and ood
Review oop and ood
 
L1-Introduction to OOPs concepts.pdf
L1-Introduction to OOPs concepts.pdfL1-Introduction to OOPs concepts.pdf
L1-Introduction to OOPs concepts.pdf
 
Concepts of oop1
Concepts of oop1Concepts of oop1
Concepts of oop1
 
OOP.pptx
OOP.pptxOOP.pptx
OOP.pptx
 
Object oriented programming
Object oriented programmingObject oriented programming
Object oriented programming
 
Overview of Object-Oriented Concepts Characteristics by vikas jagtap
Overview of Object-Oriented Concepts Characteristics by vikas jagtapOverview of Object-Oriented Concepts Characteristics by vikas jagtap
Overview of Object-Oriented Concepts Characteristics by vikas jagtap
 
Major and Minor Elements of Object Model
Major and Minor Elements of Object ModelMajor and Minor Elements of Object Model
Major and Minor Elements of Object Model
 
Object oriented programming
Object oriented programmingObject oriented programming
Object oriented programming
 
Java chapter 5
Java chapter 5Java chapter 5
Java chapter 5
 
L ab # 07
L ab # 07L ab # 07
L ab # 07
 
Chapter-OBDD.pptx
Chapter-OBDD.pptxChapter-OBDD.pptx
Chapter-OBDD.pptx
 
Introduction of OOPs
Introduction of OOPsIntroduction of OOPs
Introduction of OOPs
 
Object-Oriented Programming (OOP)
Object-Oriented Programming (OOP)Object-Oriented Programming (OOP)
Object-Oriented Programming (OOP)
 
Introduction to OOP concepts
Introduction to OOP conceptsIntroduction to OOP concepts
Introduction to OOP concepts
 
Java interfaces
Java interfacesJava interfaces
Java interfaces
 
Design Pattern Explained CH8
Design Pattern Explained CH8Design Pattern Explained CH8
Design Pattern Explained CH8
 

Plus de Markus Eisele

Stay productive while slicing up the monolith
Stay productive while slicing up the monolith Stay productive while slicing up the monolith
Stay productive while slicing up the monolith
Markus Eisele
 
Nine Neins - where Java EE will never take you
Nine Neins - where Java EE will never take youNine Neins - where Java EE will never take you
Nine Neins - where Java EE will never take you
Markus Eisele
 

Plus de Markus Eisele (20)

Sustainable Software Architecture - Open Tour DACH '22
Sustainable Software Architecture - Open Tour DACH '22Sustainable Software Architecture - Open Tour DACH '22
Sustainable Software Architecture - Open Tour DACH '22
 
Going from java message service (jms) to eda
Going from java message service (jms) to eda Going from java message service (jms) to eda
Going from java message service (jms) to eda
 
Let's be real. Quarkus in the wild.
Let's be real. Quarkus in the wild.Let's be real. Quarkus in the wild.
Let's be real. Quarkus in the wild.
 
What happens when unicorns drink coffee
What happens when unicorns drink coffeeWhat happens when unicorns drink coffee
What happens when unicorns drink coffee
 
Stateful on Stateless - The Future of Applications in the Cloud
Stateful on Stateless - The Future of Applications in the CloudStateful on Stateless - The Future of Applications in the Cloud
Stateful on Stateless - The Future of Applications in the Cloud
 
Java in the age of containers - JUG Frankfurt/M
Java in the age of containers - JUG Frankfurt/MJava in the age of containers - JUG Frankfurt/M
Java in the age of containers - JUG Frankfurt/M
 
Java in the Age of Containers and Serverless
Java in the Age of Containers and ServerlessJava in the Age of Containers and Serverless
Java in the Age of Containers and Serverless
 
Migrating from Java EE to cloud-native Reactive systems
Migrating from Java EE to cloud-native Reactive systemsMigrating from Java EE to cloud-native Reactive systems
Migrating from Java EE to cloud-native Reactive systems
 
Streaming to a new Jakarta EE / JOTB19
Streaming to a new Jakarta EE / JOTB19Streaming to a new Jakarta EE / JOTB19
Streaming to a new Jakarta EE / JOTB19
 
Cloud wars - A LavaOne discussion in seven slides
Cloud wars - A LavaOne discussion in seven slidesCloud wars - A LavaOne discussion in seven slides
Cloud wars - A LavaOne discussion in seven slides
 
Streaming to a new Jakarta EE
Streaming to a new Jakarta EEStreaming to a new Jakarta EE
Streaming to a new Jakarta EE
 
Reactive Integrations - Caveats and bumps in the road explained
Reactive Integrations - Caveats and bumps in the road explained  Reactive Integrations - Caveats and bumps in the road explained
Reactive Integrations - Caveats and bumps in the road explained
 
Stay productive while slicing up the monolith
Stay productive while slicing up the monolithStay productive while slicing up the monolith
Stay productive while slicing up the monolith
 
Stay productive while slicing up the monolith
Stay productive while slicing up the monolithStay productive while slicing up the monolith
Stay productive while slicing up the monolith
 
Stay productive_while_slicing_up_the_monolith
Stay productive_while_slicing_up_the_monolithStay productive_while_slicing_up_the_monolith
Stay productive_while_slicing_up_the_monolith
 
Architecting for failure - Why are distributed systems hard?
Architecting for failure - Why are distributed systems hard?Architecting for failure - Why are distributed systems hard?
Architecting for failure - Why are distributed systems hard?
 
Stay productive while slicing up the monolith
Stay productive while slicing up the monolith Stay productive while slicing up the monolith
Stay productive while slicing up the monolith
 
Nine Neins - where Java EE will never take you
Nine Neins - where Java EE will never take youNine Neins - where Java EE will never take you
Nine Neins - where Java EE will never take you
 
How lagom helps to build real world microservice systems
How lagom helps to build real world microservice systemsHow lagom helps to build real world microservice systems
How lagom helps to build real world microservice systems
 
CQRS and Event Sourcing for Java Developers
CQRS and Event Sourcing for Java DevelopersCQRS and Event Sourcing for Java Developers
CQRS and Event Sourcing for Java Developers
 

Dernier

Dernier (20)

Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 

All the Java ADF beginners need to know - part2

  • 1. All the Java ADF Beginners need to know! – Part 2 Markus Eisele Oracle ACE Director msg systems ag, Germany 1 Markus Eisele msg systems ag, JUNE 26 - 2011
  • 3. Overview 1. Introduction 2. Basic Object Oriented Concepts 3. Classes and Objects 4. Exceptions 5. Generics 6. Design Pattern 3 Markus Eisele msg systems ag, JUNE 26 - 2011
  • 4. Introduction • YOU„VE MISSED (or skipped) part 1 ;) (The real basics) • Let„s get more theoretical and detailed now! • Disclaimer: Even if there is “ADF” in the title, we still don’t touch ADF or even open up JDeveloper … 4 Markus Eisele msg systems ag, JUNE 26 - 2011
  • 5. Why do you have „ADF“ in the title? 5 Markus Eisele msg systems ag, JUNE 26 - 2011
  • 6. What is Object Orientation? Procedural paradigm: • Software is organized around the notion of procedures • Procedural abstraction  Works as long as the data is simple • Adding data abstractions  Groups together the pieces of data that describe some entity  Helps reduce the system‟s complexity. - Such as Records and structures Object oriented paradigm: • Organizing procedural abstractions in the context of data abstractions 6 Markus Eisele msg systems ag, JUNE 26 - 2011
  • 7. Object Orientation paradigm An approach to the solution of problems in which all computations are performed in the context of objects. • The objects are instances of classes, which:  are data abstractions  contain procedural abstractions that operation on the objects • A running program can be seen as a collection of objects collaborating to perform a given task 7 Markus Eisele msg systems ag, JUNE 26 - 2011
  • 8. Concepts that Define Object Orientation Necessary for a system or language to be object oriented (OO) • Identity  Each object is distinct from each other object, and can be referred to  Two objects are distinct even if they have the same data • Classes  The code is organized using classes, each of which describes a set of objects • Inheritance  The mechanism where features in a hierarchy inherit from superclasses to subclasses • Polymorphism  The mechanism by which several methods can have the same name and implement the same abstract operation. 8 Markus Eisele, Oracle ACE Director FMW & SOA msg systems ag, JUNE 26 - 2011
  • 9. Other Concepts • Abstraction  Object -> something in the world  Class -> objects  Superclass -> subclasses  Operation -> methods  Attributes and associations -> instance variables • Modularity  Code can be constructed entirely of classes • Encapsulation  Details can be hidden in classes  This gives rise to information hiding:  Programmers do not need to know all the details of a class 9 Markus Eisele, Oracle ACE Director FMW & SOA msg systems ag, JUNE 26 - 2011
  • 10. Classes and Objects • Object  A chunk of structured data  Has properties (attributes)  Representing it„s state  Has behaviour (methods)  Representing how it acts and reacts  Simulates the behaviour of the object in the real worl • Class  Is a unit of abstraction  It„s instances represent similar objects  Is a kind of software module  Has methods  to implement behaviour 10 Markus Eisele msg systems ag, JUNE 26 - 2011
  • 11. Class or Instance? • Something should be a class if it could have instances • Something should be an instance if it is clearly a single member of a set defined by a class • Person  Class: instances are individual persons • Markus  Instance: A person with the name: „Markus“ • … • The act of creating an object instance of a class is called the instantiation of the class.  Person markus = new Person(„Markus“); 11 Markus Eisele msg systems ag, JUNE 26 - 2011
  • 12. Name your Classes • Use capital letters  Classes always start with capital letters  E.g. CellPhone NOT cellPhone • Use singular nouns  A class is a generalization of a single object.  E.g. Person NOT Persons • Use the right level of generality  This highly depends on souroundings. Be as specific as needed.  E.g. Cat not Animal • Make sure the name has only one meaning 12 Markus Eisele msg systems ag, JUNE 26 - 2011
  • 13. Encapsulation and Class attributes and methods • Attributes and methods have visibility modifier  private Visible to all class internal methods and attributes. private List<Person> attendees;  protected Visible to all the classes within the same package and to sub-classes. protected List<Person> getAttendees();  public Visible outside the class. Public interface to access and manipulate objects public Date fromDate;  No modifier / package-private Visible outside the class. Public interface to access and manipulate objects • Class attributes and methods are marked with the keyword „static“. Can be combined with any of the above visibility modifier.  protected static int MAX_ATTENDEES; 13 Markus Eisele msg systems ag, JUNE 26 - 2011
  • 14. Inheritance • Classes can be organized into a hierarchical inheritance structure, where a child class inherits attributes from a parent class. Also known synonymously as an inheritance tree. • A child class is synonymous with the term subclass or derived class. The parent class is synonymous with the terms superclass or base class. • The inheritance tree may run many levels deep. • In a pure Object-Oriented system, a class may support multiple inheritance. public class Student extends Person { } • Always check generalizations to ensure they obey the “is a” rule:  “A Student is a Person”  “A village is a municipality” 14 Markus Eisele msg systems ag, JUNE 26 - 2011
  • 15. Abstract classes and methods • An operation should be declared to exist at the highest class in the hierarchy where it makes sense  The operation may be abstract (lacking implementation) at that level  If so, the class also must be abstract  No instances can be created  The opposite of an abstract class is a concrete class • If a superclass has an abstract operation then its subclasses at some level must have a concrete method for the operation  Leaf classes must have or inherit concrete methods for all operations  Leaf classes must be concrete public abstract class Person { public abstract String drinkingHabits(); } public class Student extends Person { public String drinkingHabits() { return "Lot of beer!"; } } 15 Markus Eisele msg systems ag, JUNE 26 - 2011
  • 16. Polymorphism • One object calls another through a message, specifying a called method. If that method is found within the receiver class, the method is invoked. If the method is not found the receiver class‟s parent class equivalent method is invoked, and so on. This behavior is called polymorphism • Polymorphism extends not only to the methods but also the attributes of an object. public class Person { private String name; private String surename; public Person(String name, String surename) { this.name = name; this.surename = surename; } } public class Student extends Person { public Student(String name, String surename) { super(name,surename); } } 16 Markus Eisele msg systems ag, JUNE 26 - 2011
  • 17. Interfaces • Like abstract classes, but cannot have executable statements  Define a set of operations that make sense in several classes  Abstract Data Types • A class can implement any number of interfaces  It must have concrete methods for the operations public interface Mammal { public abstract List<Mammal> getChildren(); } public abstract class Person implements Mammal { public List<Mammal> getChildren() { return Collections.emptyList(); } } 17 Markus Eisele msg systems ag, JUNE 26 - 2011
  • 18. Exceptions • Anything that can go wrong should result in the raising of an Exception. Exception is a class with many subclasses for specific things that can go wrong. • Use a try - catch block to trap an exception try { int x = 1/0; } catch (ArithmeticException e) { // code to handle division by zero } 18 Markus Eisele msg systems ag, JUNE 26 - 2011
  • 19. Generics • J2SE 5.0 and higher provides compile-time type safety with the Java Collections framework through generics • Generics allows you to specify, at compile-time, the types of objects you want to store in a Collection. Then when you add and get items from the list, the list already knows what types of objects are supposed to be acted on. • So you don't need to cast anything. The "<>" characters are used to designate what type is to be stored. If the wrong type of data is provided, a compile-time exception is thrown. Sample<String> object = new Sample<String>(); public class Sample<T> { private T data; public void setData(T newData) { data = newData; } public T getData() { return data; } } 19 Markus Eisele msg systems ag, JUNE 26 - 2011
  • 20. Design Pattern • The recurring aspects of designs are called design patterns.  A pattern is the outline of a reusable solution to a general problem encountered in a particular context  Many of them have been systematically documented for all software developers to use  A good pattern should  Be as general as possible  Contain a solution that has been proven to effectively solve the problem in the indicated context. Studying patterns is an effective way to learn from the experience of others 20 Markus Eisele msg systems ag, JUNE 26 - 2011
  • 21. Description of Pattern Context: • The general situation in which the pattern applies Problem:  A short sentence or two raising the main difficulty. Forces: • The issues or concerns to consider when solving the problem Solution: • The recommended way to solve the problem in the given context. —„to balance the forces‟ Antipatterns: (Optional) • Solutions that are inferior or do not work in this context. Related patterns: (Optional) • Patterns that are similar to this pattern. References: • Who developed or inspired the pattern. 21 Markus Eisele, Oracle ACE Director FMW & SOA msg systems ag, JUNE 26 - 2011
  • 22. Example Singleton Design pattern • Singletons can be used to create for example Connection Pool. If programmers create a new connection object in every class that requires it, then its clear waste of resources. In this scenario by using a singleton connection class we can maintain a single connection object which can be used throughout the application. 22 Markus Eisele, Oracle ACE Director FMW & SOA msg systems ag, JUNE 26 - 2011
  • 23. Gang of Four (GoF) Pattern Design Patterns, Elements of Reusable Object-Oriented Software - Erich Gamma, Richard Helm, Ralph Johnson, John M. ISBN: 978-0-2016-3361-0 http://bit.ly/iojEpw 23 Markus Eisele, Oracle ACE Director FMW & SOA msg systems ag, JUNE 26 - 2011
  • 24. Lesson in a tweet “Good programmers use their brains, but good guidelines save us having to think out every case.” (Francis Glassborow) http://www.devtopics.com/101-great-computer-programming-quotes/ 24 Markus Eisele, Oracle ACE Director FMW & SOA msg systems ag, 26/06/11
  • 25. Thanks! http://www.sagecomputing.com.au/ 25 Markus Eisele, Oracle ACE Director FMW & SOA msg systems ag, 26/06/11
  • 26. Thank you for your attention Markus Eisele Principle IT Architect http://blog.eisele.net http://twitter.com/myfear www.msg-systems.com www.msg-systems.com 26 Markus Eisele msg systems ag, JUNE 26 - 2011