SlideShare uma empresa Scribd logo
1 de 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

Mais conteúdo relacionado

Mais procurados

Mais procurados (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#
 

Destaque

المحاضرة+..
المحاضرة+..المحاضرة+..
المحاضرة+..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
 

Destaque (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
 

Semelhante a 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
 

Semelhante a 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
 

Mais 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
 

Mais 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
 

Último

Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024The Digital Insurer
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 

Último (20)

Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 

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