SlideShare une entreprise Scribd logo
1  sur  29
Object Oriented Principles and
           Design




                         Manish Pandit
About me
• Joined IGN in Aug 2009 to build the Social API
  Platform

• Worked at E*Trade, Accenture, WaMu, BEA

• Started working with Java ecosystem in ’96

• @lobster1234 on Twitter, Slideshare, Github and
  StackOverflow
Programming
• What constitutes a ‘program’?
  – Data
  – Behavior
Procedural Code
#include<stdio.h>
int main(){
 int what, result;
 printf("nFactorial of what, fellow code-foo’er? t");
 scanf("%d",&what);
 result = function(what);
 printf("nThe number you are looking for is %d n", result);
}

int function(int number){
  int result;
  if(number==1) return 1;
  else result = number*function(number -1);
  return result;

}
Lets analyze..
• Simple to write, as it is linear. Think machine.
• Can kick any OO language’s ass in performance
                              BUT
• No separation of data and behavior
• No concept of visibility of variables
• No encapsulation
• Hard to map real world problems as humans – great for
  algorithms though.
• Global, shared data.
• Reusability achieved via copy paste, header files (.h) or
  shared object files (.so files in Unix)
Objects – What?
• Abstraction over linear programming
• Keywords – reduce, reuse, recycle
• Modeling a problem around data and
  behavior vs. a big block of code
• Identify patterns to model
  – Classes
  – Methods
• HUMAN!
Confused?
• Let me confuse you more with the cliché,
  textbook examples of
  – Shapes (Circle, Triangle, Rectangle, Square)
  – Animals (Dog, Cat, Pig, Tiger)
  – Vehicles (Car, Truck, Bike)
We can do better!
• Lets model IGN the OO-way
  – We have games
  – We have properties of games
  – We have users (who have properties too)
  – Users follow games
  – Users follow other users
  – Users rate games
  – Users update status
Real world enough for you?
• Actors – Nouns – Users, Games, Activities,
  Status
• Actions – Verbs – Rate, Follow, Update
• Properties
  – User – nickname, age, gender
  – Game – publisher, title, description
Connect the dots
• Actors, Nouns – are Classes
• Actions, Verbs – are functions or methods
• A function operates on data encapsulated within
  a Class
• Every actor has certain properties
• A caller of this Class doesn’t give a shit to the
  implementation details (abstraction, data hiding)
• Collectively, the properties and methods in a class
  are called its members.
Going back to C

#include<stdio.h>
int main(){

        char* title; char* publisher;

//      save??
//      describe??

}
Java
public class Game {

         private String title;
         private String publisher;

          public String getTitle(){
                    return "Title is " + title;
          }
          public void setTitle(String title){
                    if(title!=null)
                              this.title = title;
                    else this.title = "";
          }
          public String getPublisher(){
                    return "Publisher is " + publisher;
          }
          public void setPublisher(String publisher){
                    this.publisher = publisher;
          }
          public void describe(){
                    System.out.println(“Title is “ + title + “ Publisher is “ +
publisher);
          }
}
Principles so far..
• Objects are instances of classes and are created
  by invoking the constructor which is defined in a
  class.
• Objects have a state and identity, classes don’t.
• Some classes cannot be instantiated as objects
   – Abstract classes
   – Factories (getting a little ahead of ourselves here!)
• Properties are defined by “has-a” clause
• Classes are defined by “is-a” clause (more on this
  later)
Inheritance
• Classes can extend other classes and interfaces
  – is-a relationship
     • A Game is a MediaObject, so is a DVD
     • A User is a Person, so is an Editor
• Java does not support multiple inheritance per-
  se, but you can mimic that via interfaces.
• A cluster of parent-child nodes is called a
  hierarchy
• CS Students – Generalization vs. Specialization
Inheritance and Behavior
• Child classes can
  – override behavior
  – overload behavior

  Provided the Parent has provided visibility to its
  members
Association: Aggregation
• A game has a title
• A game has a publisher
  – A Publisher can live without this game. He can
    have other games. This is aggregation.
Association: Composition
• A game has a story
  – A story cannot live outside of the game. This is
    composition
Behavior : Interfaces
• An interface defines a behavior of the classes
  that inherit it – as seen by the consumers
• Interfaces are actions on verbs – like
  Observable, Serializable, Mutable,
  Comparable. They add behavior.
• Interfaces do not define implementation
  (that’s OO Power!). They just define behavior.
  The implementation is encapsulated within
  the class. This is polymorphism.
Behavior of saving data
•   Interface:
     public interface Persistable{
          public void save(Object o);
     }

•   Implementations:
     public class MySQLStore implements Persistable{
          public void save(Object o){
                     //save in MySQL
          }
     }

     public class MongoStore implements Persistable{
          public void save(Object o){
                    //save in MongoDB
          }
     }
Packages
• Packages for logical organization
Visibility and Modifiers
• public/protected/package/private
  – Scala has explicit package-private
  – Accessors and Mutators
• Advanced for this session
  – final
  – static
  – constructors (default, noargs..)
  – super
Recap : Object Modeling
•   Nouns, Verbs
•   is-a, has-a
•   Inheritance (is-a)
•   Association (has-a)
    – Composition
    – Aggregation
• Data vs. Behavior
Design Patterns
•   Singleton
•   Adapter
•   Decorator
•   Proxy
•   Iterator
•   Template
•   Strategy
•   Factory Method
Advanced OO
• Polymorphism
  – Dynamic/runtime binding
• Mix-ins
  – Traits in Scala
• Frameworks
  – Frameworks like Scalatra, Struts, Grails..
  – Spring, Shindig
Case Study : IGNSocial
•   Interfaces
•   Implementation
•   Packages
•   Dependencies
Java Collections API
• Go over the javadoc of collections API and
  identify
  – Packages
  – Inheritance
     • Classes
     • Interfaces
Collections Type Hierarchy
Factorial in Scala

   def fact(x:Int):Int=if(x==1) x else x*fact(x-1)
Further Reading
• Apache Commons Library
  – Connection Pool
  – String and Calendar Utils
  – JDBC
• Java or C++ Language Spec
• Wikipedia

Contenu connexe

Tendances (17)

[OOP - Lec 01] Introduction to OOP
[OOP - Lec 01] Introduction to OOP[OOP - Lec 01] Introduction to OOP
[OOP - Lec 01] Introduction to OOP
 
Python Lecture 13
Python Lecture 13Python Lecture 13
Python Lecture 13
 
Oop
OopOop
Oop
 
Java object oriented programming concepts - Brainsmartlabs
Java object oriented programming concepts - BrainsmartlabsJava object oriented programming concepts - Brainsmartlabs
Java object oriented programming concepts - Brainsmartlabs
 
Java
JavaJava
Java
 
Java essentials for hadoop
Java essentials for hadoopJava essentials for hadoop
Java essentials for hadoop
 
Java for the Beginners
Java for the BeginnersJava for the Beginners
Java for the Beginners
 
[OOP - Lec 06] Classes and Objects
[OOP - Lec 06] Classes and Objects[OOP - Lec 06] Classes and Objects
[OOP - Lec 06] Classes and Objects
 
GeekAustin PHP Class - Session 6
GeekAustin PHP Class - Session 6GeekAustin PHP Class - Session 6
GeekAustin PHP Class - Session 6
 
Metaprogramming ruby
Metaprogramming rubyMetaprogramming ruby
Metaprogramming ruby
 
OOP Basics
OOP BasicsOOP Basics
OOP Basics
 
Object Oriented Paradigm
Object Oriented ParadigmObject Oriented Paradigm
Object Oriented Paradigm
 
Pi j3.1 inheritance
Pi j3.1 inheritancePi j3.1 inheritance
Pi j3.1 inheritance
 
Object Oriented Programming Principles
Object Oriented Programming PrinciplesObject Oriented Programming Principles
Object Oriented Programming Principles
 
2. Basics of Java
2. Basics of Java2. Basics of Java
2. Basics of Java
 
Oops concept on c#
Oops concept on c#Oops concept on c#
Oops concept on c#
 
Object oriented programming With C#
Object oriented programming With C#Object oriented programming With C#
Object oriented programming With C#
 

En vedette

المحاضرة+..
المحاضرة+..المحاضرة+..
المحاضرة+..Fawaz Gogo
 
設計英文
設計英文設計英文
設計英文h6533n
 
Giao trinh tu tuong ho chi minh
Giao trinh tu tuong ho chi minhGiao trinh tu tuong ho chi minh
Giao trinh tu tuong ho chi minhNguyen Van Hoa
 
De Ziekenzalving
De ZiekenzalvingDe Ziekenzalving
De ZiekenzalvingN Couperus
 
Future Agenda Future Of Food
Future Agenda   Future Of FoodFuture Agenda   Future Of Food
Future Agenda Future Of FoodFuture Agenda
 
Future Agenda Future Of Work
Future Agenda   Future Of WorkFuture Agenda   Future Of Work
Future Agenda Future Of WorkFuture Agenda
 
C Level Client Presentation
C Level Client PresentationC Level Client Presentation
C Level Client PresentationThomas Noon
 
Ipeec workshop, 18 20 oct 2011 (beni-asean energy efficiency action plan) pub...
Ipeec workshop, 18 20 oct 2011 (beni-asean energy efficiency action plan) pub...Ipeec workshop, 18 20 oct 2011 (beni-asean energy efficiency action plan) pub...
Ipeec workshop, 18 20 oct 2011 (beni-asean energy efficiency action plan) pub...benisuryadi
 
πιλοτικο προγραμμα σπουδων στις φυσικες επιστημες
πιλοτικο προγραμμα σπουδων στις φυσικες επιστημεςπιλοτικο προγραμμα σπουδων στις φυσικες επιστημες
πιλοτικο προγραμμα σπουδων στις φυσικες επιστημεςChristos Gotzaridis
 
Pictures For Music Magazine
Pictures For Music MagazinePictures For Music Magazine
Pictures For Music Magazinebenjo7
 
20130904 splash maps
20130904 splash maps20130904 splash maps
20130904 splash mapsdbyhundred
 
Future Learning Landscape Introduction
Future Learning Landscape IntroductionFuture Learning Landscape Introduction
Future Learning Landscape IntroductionYvan Peter
 
13112282 Aig Risk Bankruptcy Report
13112282 Aig Risk Bankruptcy Report13112282 Aig Risk Bankruptcy Report
13112282 Aig Risk Bankruptcy Reportjubin6025
 
MongoSF 2011 - Using MongoDB for IGN's Social Platform
MongoSF 2011 - Using MongoDB for IGN's Social PlatformMongoSF 2011 - Using MongoDB for IGN's Social Platform
MongoSF 2011 - Using MongoDB for IGN's Social PlatformManish Pandit
 
Fonts N Tht
Fonts N ThtFonts N Tht
Fonts N Thtbenjo7
 
中秋快樂
中秋快樂中秋快樂
中秋快樂Roc4031
 
Fonts N Tht
Fonts N ThtFonts N Tht
Fonts N Thtbenjo7
 
المحاضرة+..
المحاضرة+..المحاضرة+..
المحاضرة+..Fawaz Gogo
 

En vedette (20)

المحاضرة+..
المحاضرة+..المحاضرة+..
المحاضرة+..
 
設計英文
設計英文設計英文
設計英文
 
Giao trinh tu tuong ho chi minh
Giao trinh tu tuong ho chi minhGiao trinh tu tuong ho chi minh
Giao trinh tu tuong ho chi minh
 
De Ziekenzalving
De ZiekenzalvingDe Ziekenzalving
De Ziekenzalving
 
Future Agenda Future Of Food
Future Agenda   Future Of FoodFuture Agenda   Future Of Food
Future Agenda Future Of Food
 
Future Agenda Future Of Work
Future Agenda   Future Of WorkFuture Agenda   Future Of Work
Future Agenda Future Of Work
 
C Level Client Presentation
C Level Client PresentationC Level Client Presentation
C Level Client Presentation
 
Ipeec workshop, 18 20 oct 2011 (beni-asean energy efficiency action plan) pub...
Ipeec workshop, 18 20 oct 2011 (beni-asean energy efficiency action plan) pub...Ipeec workshop, 18 20 oct 2011 (beni-asean energy efficiency action plan) pub...
Ipeec workshop, 18 20 oct 2011 (beni-asean energy efficiency action plan) pub...
 
Acacia Research and Learning Forum Tutorial 2
Acacia Research and Learning Forum Tutorial 2Acacia Research and Learning Forum Tutorial 2
Acacia Research and Learning Forum Tutorial 2
 
πιλοτικο προγραμμα σπουδων στις φυσικες επιστημες
πιλοτικο προγραμμα σπουδων στις φυσικες επιστημεςπιλοτικο προγραμμα σπουδων στις φυσικες επιστημες
πιλοτικο προγραμμα σπουδων στις φυσικες επιστημες
 
Pictures For Music Magazine
Pictures For Music MagazinePictures For Music Magazine
Pictures For Music Magazine
 
20130904 splash maps
20130904 splash maps20130904 splash maps
20130904 splash maps
 
Future Learning Landscape Introduction
Future Learning Landscape IntroductionFuture Learning Landscape Introduction
Future Learning Landscape Introduction
 
13112282 Aig Risk Bankruptcy Report
13112282 Aig Risk Bankruptcy Report13112282 Aig Risk Bankruptcy Report
13112282 Aig Risk Bankruptcy Report
 
MongoSF 2011 - Using MongoDB for IGN's Social Platform
MongoSF 2011 - Using MongoDB for IGN's Social PlatformMongoSF 2011 - Using MongoDB for IGN's Social Platform
MongoSF 2011 - Using MongoDB for IGN's Social Platform
 
Fonts N Tht
Fonts N ThtFonts N Tht
Fonts N Tht
 
中秋快樂
中秋快樂中秋快樂
中秋快樂
 
Fonts N Tht
Fonts N ThtFonts N Tht
Fonts N Tht
 
المحاضرة+..
المحاضرة+..المحاضرة+..
المحاضرة+..
 
Story Board & Planning
Story Board & PlanningStory Board & Planning
Story Board & Planning
 

Similaire à Object Oriented Principles and Design in Java

Introduction to Machine Learning
Introduction to Machine LearningIntroduction to Machine Learning
Introduction to Machine LearningRahul Jain
 
cs213Lecture_1 java programming oopsss.pptx
cs213Lecture_1 java programming oopsss.pptxcs213Lecture_1 java programming oopsss.pptx
cs213Lecture_1 java programming oopsss.pptxmshanajoel6
 
Complete PPT about the Java lokesh kept it
Complete PPT about the Java lokesh kept itComplete PPT about the Java lokesh kept it
Complete PPT about the Java lokesh kept itlokeshpappaka10
 
Introduction to Software - Coder Forge - John Mulhall
Introduction to Software - Coder Forge - John MulhallIntroduction to Software - Coder Forge - John Mulhall
Introduction to Software - Coder Forge - John MulhallJohn Mulhall
 
Google App Engine - exploiting limitations
Google App Engine - exploiting limitationsGoogle App Engine - exploiting limitations
Google App Engine - exploiting limitationsTomáš Holas
 
Buidling large scale recommendation engine
Buidling large scale recommendation engineBuidling large scale recommendation engine
Buidling large scale recommendation engineKeeyong Han
 
Java for android developers
Java for android developersJava for android developers
Java for android developersAly Abdelkareem
 
Facets and Pivoting for Flexible and Usable Linked Data Exploration
Facets and Pivoting for Flexible and Usable Linked Data ExplorationFacets and Pivoting for Flexible and Usable Linked Data Exploration
Facets and Pivoting for Flexible and Usable Linked Data ExplorationRoberto García
 
Md02 - Getting Started part-2
Md02 - Getting Started part-2Md02 - Getting Started part-2
Md02 - Getting Started part-2Rakesh Madugula
 
Programming in java basics
Programming in java  basicsProgramming in java  basics
Programming in java basicsLovelitJose
 

Similaire à Object Oriented Principles and Design in Java (20)

Java for beginners
Java for beginnersJava for beginners
Java for beginners
 
Introduction to Machine Learning
Introduction to Machine LearningIntroduction to Machine Learning
Introduction to Machine Learning
 
C# by Zaheer Abbas Aghani
C# by Zaheer Abbas AghaniC# by Zaheer Abbas Aghani
C# by Zaheer Abbas Aghani
 
cs213Lecture_1 java programming oopsss.pptx
cs213Lecture_1 java programming oopsss.pptxcs213Lecture_1 java programming oopsss.pptx
cs213Lecture_1 java programming oopsss.pptx
 
Complete PPT about the Java lokesh kept it
Complete PPT about the Java lokesh kept itComplete PPT about the Java lokesh kept it
Complete PPT about the Java lokesh kept it
 
Introduction to Software - Coder Forge - John Mulhall
Introduction to Software - Coder Forge - John MulhallIntroduction to Software - Coder Forge - John Mulhall
Introduction to Software - Coder Forge - John Mulhall
 
Google App Engine - exploiting limitations
Google App Engine - exploiting limitationsGoogle App Engine - exploiting limitations
Google App Engine - exploiting limitations
 
Buidling large scale recommendation engine
Buidling large scale recommendation engineBuidling large scale recommendation engine
Buidling large scale recommendation engine
 
Java for android developers
Java for android developersJava for android developers
Java for android developers
 
Introduction to c ++ part -1
Introduction to c ++   part -1Introduction to c ++   part -1
Introduction to c ++ part -1
 
Facets and Pivoting for Flexible and Usable Linked Data Exploration
Facets and Pivoting for Flexible and Usable Linked Data ExplorationFacets and Pivoting for Flexible and Usable Linked Data Exploration
Facets and Pivoting for Flexible and Usable Linked Data Exploration
 
Object oriented programming
Object oriented programmingObject oriented programming
Object oriented programming
 
Md02 - Getting Started part-2
Md02 - Getting Started part-2Md02 - Getting Started part-2
Md02 - Getting Started part-2
 
Programming in java basics
Programming in java  basicsProgramming in java  basics
Programming in java basics
 
RIBBUN SOFTWARE
RIBBUN SOFTWARERIBBUN SOFTWARE
RIBBUN SOFTWARE
 
Java01
Java01Java01
Java01
 
Java01
Java01Java01
Java01
 
Java01
Java01Java01
Java01
 
Java01
Java01Java01
Java01
 
Introduction what is java
Introduction what is javaIntroduction what is java
Introduction what is java
 

Plus de Manish Pandit

Disaster recovery - What, Why, and How
Disaster recovery - What, Why, and HowDisaster recovery - What, Why, and How
Disaster recovery - What, Why, and HowManish Pandit
 
Serverless Architectures on AWS in practice - OSCON 2018
Serverless Architectures on AWS in practice - OSCON 2018Serverless Architectures on AWS in practice - OSCON 2018
Serverless Architectures on AWS in practice - OSCON 2018Manish Pandit
 
Disaster Recovery and Reliability
Disaster Recovery and ReliabilityDisaster Recovery and Reliability
Disaster Recovery and ReliabilityManish Pandit
 
Immutable AWS Deployments with Packer and Jenkins
Immutable AWS Deployments with Packer and JenkinsImmutable AWS Deployments with Packer and Jenkins
Immutable AWS Deployments with Packer and JenkinsManish Pandit
 
AWS Lambda with Serverless Framework and Java
AWS Lambda with Serverless Framework and JavaAWS Lambda with Serverless Framework and Java
AWS Lambda with Serverless Framework and JavaManish Pandit
 
AWS Primer and Quickstart
AWS Primer and QuickstartAWS Primer and Quickstart
AWS Primer and QuickstartManish Pandit
 
Securing your APIs with OAuth, OpenID, and OpenID Connect
Securing your APIs with OAuth, OpenID, and OpenID ConnectSecuring your APIs with OAuth, OpenID, and OpenID Connect
Securing your APIs with OAuth, OpenID, and OpenID ConnectManish Pandit
 
Silicon Valley 2014 - API Antipatterns
Silicon Valley 2014 - API AntipatternsSilicon Valley 2014 - API Antipatterns
Silicon Valley 2014 - API AntipatternsManish Pandit
 
Scalabay - API Design Antipatterns
Scalabay - API Design AntipatternsScalabay - API Design Antipatterns
Scalabay - API Design AntipatternsManish Pandit
 
OSCON 2014 - API Ecosystem with Scala, Scalatra, and Swagger at Netflix
OSCON 2014 - API Ecosystem with Scala, Scalatra, and Swagger at NetflixOSCON 2014 - API Ecosystem with Scala, Scalatra, and Swagger at Netflix
OSCON 2014 - API Ecosystem with Scala, Scalatra, and Swagger at NetflixManish Pandit
 
API Design Antipatterns - APICon SF
API Design Antipatterns - APICon SFAPI Design Antipatterns - APICon SF
API Design Antipatterns - APICon SFManish Pandit
 
Motivation : it Matters
Motivation : it MattersMotivation : it Matters
Motivation : it MattersManish Pandit
 
Building Apis in Scala with Playframework2
Building Apis in Scala with Playframework2Building Apis in Scala with Playframework2
Building Apis in Scala with Playframework2Manish Pandit
 
Introducing Scala to your Ruby/Java Shop : My experiences at IGN
Introducing Scala to your Ruby/Java Shop : My experiences at IGNIntroducing Scala to your Ruby/Java Shop : My experiences at IGN
Introducing Scala to your Ruby/Java Shop : My experiences at IGNManish Pandit
 
Evolving IGN’s New APIs with Scala
 Evolving IGN’s New APIs with Scala Evolving IGN’s New APIs with Scala
Evolving IGN’s New APIs with ScalaManish Pandit
 
Silicon Valley Code Camp 2011: Play! as you REST
Silicon Valley Code Camp 2011: Play! as you RESTSilicon Valley Code Camp 2011: Play! as you REST
Silicon Valley Code Camp 2011: Play! as you RESTManish Pandit
 

Plus de Manish Pandit (20)

Disaster recovery - What, Why, and How
Disaster recovery - What, Why, and HowDisaster recovery - What, Why, and How
Disaster recovery - What, Why, and How
 
Serverless Architectures on AWS in practice - OSCON 2018
Serverless Architectures on AWS in practice - OSCON 2018Serverless Architectures on AWS in practice - OSCON 2018
Serverless Architectures on AWS in practice - OSCON 2018
 
Disaster Recovery and Reliability
Disaster Recovery and ReliabilityDisaster Recovery and Reliability
Disaster Recovery and Reliability
 
OAuth2 primer
OAuth2 primerOAuth2 primer
OAuth2 primer
 
Immutable AWS Deployments with Packer and Jenkins
Immutable AWS Deployments with Packer and JenkinsImmutable AWS Deployments with Packer and Jenkins
Immutable AWS Deployments with Packer and Jenkins
 
AWS Lambda with Serverless Framework and Java
AWS Lambda with Serverless Framework and JavaAWS Lambda with Serverless Framework and Java
AWS Lambda with Serverless Framework and Java
 
AWS Primer and Quickstart
AWS Primer and QuickstartAWS Primer and Quickstart
AWS Primer and Quickstart
 
Securing your APIs with OAuth, OpenID, and OpenID Connect
Securing your APIs with OAuth, OpenID, and OpenID ConnectSecuring your APIs with OAuth, OpenID, and OpenID Connect
Securing your APIs with OAuth, OpenID, and OpenID Connect
 
Silicon Valley 2014 - API Antipatterns
Silicon Valley 2014 - API AntipatternsSilicon Valley 2014 - API Antipatterns
Silicon Valley 2014 - API Antipatterns
 
Scalabay - API Design Antipatterns
Scalabay - API Design AntipatternsScalabay - API Design Antipatterns
Scalabay - API Design Antipatterns
 
OSCON 2014 - API Ecosystem with Scala, Scalatra, and Swagger at Netflix
OSCON 2014 - API Ecosystem with Scala, Scalatra, and Swagger at NetflixOSCON 2014 - API Ecosystem with Scala, Scalatra, and Swagger at Netflix
OSCON 2014 - API Ecosystem with Scala, Scalatra, and Swagger at Netflix
 
API Design Antipatterns - APICon SF
API Design Antipatterns - APICon SFAPI Design Antipatterns - APICon SF
API Design Antipatterns - APICon SF
 
Motivation : it Matters
Motivation : it MattersMotivation : it Matters
Motivation : it Matters
 
Building Apis in Scala with Playframework2
Building Apis in Scala with Playframework2Building Apis in Scala with Playframework2
Building Apis in Scala with Playframework2
 
Scala at Netflix
Scala at NetflixScala at Netflix
Scala at Netflix
 
Introducing Scala to your Ruby/Java Shop : My experiences at IGN
Introducing Scala to your Ruby/Java Shop : My experiences at IGNIntroducing Scala to your Ruby/Java Shop : My experiences at IGN
Introducing Scala to your Ruby/Java Shop : My experiences at IGN
 
Evolving IGN’s New APIs with Scala
 Evolving IGN’s New APIs with Scala Evolving IGN’s New APIs with Scala
Evolving IGN’s New APIs with Scala
 
IGN's V3 API
IGN's V3 APIIGN's V3 API
IGN's V3 API
 
Java and the JVM
Java and the JVMJava and the JVM
Java and the JVM
 
Silicon Valley Code Camp 2011: Play! as you REST
Silicon Valley Code Camp 2011: Play! as you RESTSilicon Valley Code Camp 2011: Play! as you REST
Silicon Valley Code Camp 2011: Play! as you REST
 

Dernier

Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
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 2024Rafal Los
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 

Dernier (20)

Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
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
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 

Object Oriented Principles and Design in Java

  • 1. Object Oriented Principles and Design Manish Pandit
  • 2. About me • Joined IGN in Aug 2009 to build the Social API Platform • Worked at E*Trade, Accenture, WaMu, BEA • Started working with Java ecosystem in ’96 • @lobster1234 on Twitter, Slideshare, Github and StackOverflow
  • 3. Programming • What constitutes a ‘program’? – Data – Behavior
  • 4. Procedural Code #include<stdio.h> int main(){ int what, result; printf("nFactorial of what, fellow code-foo’er? t"); scanf("%d",&what); result = function(what); printf("nThe number you are looking for is %d n", result); } int function(int number){ int result; if(number==1) return 1; else result = number*function(number -1); return result; }
  • 5. Lets analyze.. • Simple to write, as it is linear. Think machine. • Can kick any OO language’s ass in performance BUT • No separation of data and behavior • No concept of visibility of variables • No encapsulation • Hard to map real world problems as humans – great for algorithms though. • Global, shared data. • Reusability achieved via copy paste, header files (.h) or shared object files (.so files in Unix)
  • 6. Objects – What? • Abstraction over linear programming • Keywords – reduce, reuse, recycle • Modeling a problem around data and behavior vs. a big block of code • Identify patterns to model – Classes – Methods • HUMAN!
  • 7. Confused? • Let me confuse you more with the cliché, textbook examples of – Shapes (Circle, Triangle, Rectangle, Square) – Animals (Dog, Cat, Pig, Tiger) – Vehicles (Car, Truck, Bike)
  • 8. We can do better! • Lets model IGN the OO-way – We have games – We have properties of games – We have users (who have properties too) – Users follow games – Users follow other users – Users rate games – Users update status
  • 9. Real world enough for you? • Actors – Nouns – Users, Games, Activities, Status • Actions – Verbs – Rate, Follow, Update • Properties – User – nickname, age, gender – Game – publisher, title, description
  • 10. Connect the dots • Actors, Nouns – are Classes • Actions, Verbs – are functions or methods • A function operates on data encapsulated within a Class • Every actor has certain properties • A caller of this Class doesn’t give a shit to the implementation details (abstraction, data hiding) • Collectively, the properties and methods in a class are called its members.
  • 11. Going back to C #include<stdio.h> int main(){ char* title; char* publisher; // save?? // describe?? }
  • 12. Java public class Game { private String title; private String publisher; public String getTitle(){ return "Title is " + title; } public void setTitle(String title){ if(title!=null) this.title = title; else this.title = ""; } public String getPublisher(){ return "Publisher is " + publisher; } public void setPublisher(String publisher){ this.publisher = publisher; } public void describe(){ System.out.println(“Title is “ + title + “ Publisher is “ + publisher); } }
  • 13. Principles so far.. • Objects are instances of classes and are created by invoking the constructor which is defined in a class. • Objects have a state and identity, classes don’t. • Some classes cannot be instantiated as objects – Abstract classes – Factories (getting a little ahead of ourselves here!) • Properties are defined by “has-a” clause • Classes are defined by “is-a” clause (more on this later)
  • 14. Inheritance • Classes can extend other classes and interfaces – is-a relationship • A Game is a MediaObject, so is a DVD • A User is a Person, so is an Editor • Java does not support multiple inheritance per- se, but you can mimic that via interfaces. • A cluster of parent-child nodes is called a hierarchy • CS Students – Generalization vs. Specialization
  • 15. Inheritance and Behavior • Child classes can – override behavior – overload behavior Provided the Parent has provided visibility to its members
  • 16. Association: Aggregation • A game has a title • A game has a publisher – A Publisher can live without this game. He can have other games. This is aggregation.
  • 17. Association: Composition • A game has a story – A story cannot live outside of the game. This is composition
  • 18. Behavior : Interfaces • An interface defines a behavior of the classes that inherit it – as seen by the consumers • Interfaces are actions on verbs – like Observable, Serializable, Mutable, Comparable. They add behavior. • Interfaces do not define implementation (that’s OO Power!). They just define behavior. The implementation is encapsulated within the class. This is polymorphism.
  • 19. Behavior of saving data • Interface: public interface Persistable{ public void save(Object o); } • Implementations: public class MySQLStore implements Persistable{ public void save(Object o){ //save in MySQL } } public class MongoStore implements Persistable{ public void save(Object o){ //save in MongoDB } }
  • 20. Packages • Packages for logical organization
  • 21. Visibility and Modifiers • public/protected/package/private – Scala has explicit package-private – Accessors and Mutators • Advanced for this session – final – static – constructors (default, noargs..) – super
  • 22. Recap : Object Modeling • Nouns, Verbs • is-a, has-a • Inheritance (is-a) • Association (has-a) – Composition – Aggregation • Data vs. Behavior
  • 23. Design Patterns • Singleton • Adapter • Decorator • Proxy • Iterator • Template • Strategy • Factory Method
  • 24. Advanced OO • Polymorphism – Dynamic/runtime binding • Mix-ins – Traits in Scala • Frameworks – Frameworks like Scalatra, Struts, Grails.. – Spring, Shindig
  • 25. Case Study : IGNSocial • Interfaces • Implementation • Packages • Dependencies
  • 26. Java Collections API • Go over the javadoc of collections API and identify – Packages – Inheritance • Classes • Interfaces
  • 28. Factorial in Scala def fact(x:Int):Int=if(x==1) x else x*fact(x-1)
  • 29. Further Reading • Apache Commons Library – Connection Pool – String and Calendar Utils – JDBC • Java or C++ Language Spec • Wikipedia