SlideShare ist ein Scribd-Unternehmen logo
1 von 52
Downloaden Sie, um offline zu lesen
Introduction to

Object Oriented Programming



            Mumbai
What is an object?

       Dog


      Snowy
Dog is a generalization of Snowy


                               Dog



            Animal


                               Snowy




Subclass?
Dog



                Animal


                         Bird




Polymorphism?
object

                Real world abstractions

                      Encapsulate state
                    represent information
 state
                     Communicate by
                     Message passing
behavior
                May execute in sequence
                     Or in parallel
name




state




          behavior
inheritance       encapsulation




       Building
        blocks               polymorphism
Inheritance lets you build classes based on other
 classes, thus avoiding duplicating and repeating
                       code
When a class inherits from another,
Polymorphism allows a subclass to standin for a
                 superclass


       duck


      cuckoo
                            Bird.flapWings()

       ostrich
Encapsulation is to hide the internal
representation of the object from view outside
               object definition



                 Car.drive()
                                     Car

                                    drive()
camry
                 car
                                accord

                                          Vehicle              toyota
                 motorcycle

                              honda                 Harley-davidson

civic
                                         corolla



        5 mins
Object Oriented
Solutions


for
What the stakeholders
                         want

   1

                              Add flexibility,
                              Remove duplication
                              Encapsulation,
                 2            Inheritance,
                              Polymorphism




                     3


Apply patterns
Loose coupling
Delegation
We have a product which collects checks from
      various banks and processes them.
The process includes sending out email, a fax or
          storing a scan for the check.
Pay attention to the nouns (person, place or thing)
            they are object candidates

    The verbs would be the possible methods

          This is called textual analysis
We have a product which collects checks from
      various banks and processes them.
The process includes sending out email, a fax or
          storing a scan for the check.




       5 mins
We have a product which collects checks from
      various banks and processes them.
The process includes sending out email, a fax or
          storing a scan for the check.
FastProcessor


 process(check:Check)                       Bank
sendEmail(check:Check)
 sendFax(check:Check)
   scan(check:Check)
                          *
                             Check
                         ----------------
                          bank:Bank
object interactions
case class Bank(id:Int, name:String)
 case class Check(number:Int, bank:Bank)

 class FastProcessor {

 def process(checks:List[Check]) = checks foreach (check => sendEmail)

 def sendEmail = println("Email sent")

 }

val citibank = new Bank(1, "Citibank")          //> citibank :
com.baml.ooad.Bank = Bank(1,Citibank)
(new FastProcessor).process(List(new Check(1,citibank), new Check(2,citibank)))
                                                  //> Email sent
                                                  //| Email sent
We need to support BoA as well and that sends
                   Faxes
We dont touch the design
case class Bank(id:Int, name:String)
  case class Check(number:Int, bank:Bank)

  class FastProcessor {

  def process(checks:List[Check]) = checks foreach (check => if
(check.bank.name=="Citibank") sendEmail else sendFax)

  def sendEmail = println("Email sent")
  def sendFax = println("Fax sent")

  }

  val citibank = new Bank(1, "Citibank")          //
  val bankOfAmerica = new Bank(2, "BoA")
          //
  val citibankCheckList = List(new Check(1,citibank), new Check(2,citibank))
  val bankOfAmericaCheckList = List(new Check(1,bankOfAmerica), new
Check(2,bankOfAmerica))

  (new FastProcessor).process(citibankCheckList ::: bankOfAmericaCheckList)
                                                  //> Email sent
                                                  //| Email sent
                                                  //| Fax sent
                                                  //| Fax sent
We need to support HDFC and ICICI as well now!
good design == flexible design




whenever there is a change encapsulate it

    5 mins
What the stakeholders
                         want

   1

                              Add flexibility,
                              Remove duplication
                              Encapsulation,
                 2            Inheritance,
                              Polymorphism




                     3


Apply patterns
Loose coupling
Delegation
trait Bank {
    def process(check: Check)
  }

 object CitiBank extends Bank {
   val name = "CitiBank"
   def process(check: Check) = sendEmail
   def sendEmail = println("Email sent")

 }

 object BankOfAmerica extends Bank {
   val name = "BoA"
   def process(check: Check) = sendFax
   def sendFax = println("Fax sent")

 }

 object HDFC extends Bank {
   val name = "HDFC"
   def process(check: Check) = {sendFax; sendEmail}

     def sendEmail = println("Email sent")
     def sendFax = println("Fax sent")

 }

 case class Check(number: Int, bank: Bank)
class FastProcessor {

    def process(checks: List[Check]) = checks foreach (check =>
check.bank.process(check))

 }

  val citibankCheckList = List(new Check(1, CitiBank), new Check(2,
CitiBank))
  val bankOfAmericaCheckList = List(new Check(1, BankOfAmerica), new
Check(2, BankOfAmerica))

 val hdfcCheckList = List(new Check(1, HDFC))

  (new FastProcessor).process(citibankCheckList :::
bankOfAmericaCheckList ::: hdfcCheckList)
                                                  //>   Email sent
                                                  //|   Email sent
                                                  //|   Fax sent
                                                  //|   Fax sent
                                                  //|   Fax sent
                                                  //|   Email sent
bank
                                 FastProcessor




HDFC   BoA    Citibank


                         Check
bank
                                 FastProcessor




HDFC   BoA    Citibank


                         Check
Code to interfaces – makes software easy to
                    extend

Encapsulate what varies – protect classes from
                  changes

  Each class should have only one reason to
                   change
What the stakeholders
                         want

   1
                                Add flexibility,
                                Remove duplication
                                Encapsulation,
                                Inheritance,
                 2              Polymorphism




                     3


Apply patterns
Loose coupling
Delegation
OO Principles



result in maintenable, flexible and extensible
                  software
Open Closed Principle

Classes should be open for extension and closed
                for modification
bank




HDFC    BoA   Citibank



                         Any number of banks?
DRY

           Don't repeat yourself


All duplicate code should be encapsulated /
                 abstracted
bank
                                         FastProcessor




HDFC        BoA       Citibank


                                 Check




       CommunicationUtils
What the stakeholders
                         want

   1
                                Add flexibility,
                                Remove duplication
                                Encapsulation,
                                Inheritance,
                 2              Polymorphism




                     3


Apply patterns
Loose coupling
Delegation
Single Responsibility Principle


Each object should have only one reason to
                  change
What methods should really belong to
Automobile?
Liskov Substitution Principle




Subtypes MUST be substitutable for their base
                  types

      Ensures well designed inheritance
Is this valid?
class Rectangle {
   var height: Int = 0
   var width: Int = 0
   def setHeight(h: Int) = { height = h }
   def setWidth(w: Int) = { width = w }
 }

 class Square extends Rectangle {
   override def setHeight(h: Int) = { height = h; width = h }
   override def setWidth(w: Int) = { width = w; height = w }
 }

 val rectangle = new Square

 rectangle.setHeight(10)
 rectangle.setWidth(5)

  assert(10 == rectangle.height)                //>
java.lang.AssertionError: assertion failed
There are multiple options other than

             inheritance
Delegation

 When once class hands off the task of doing
           something to another

Useful when you want to use the functionality of
  another class without changing its behavior
bank




HDFC   BoA      Citibank




       We delegated processing to individual banks
Composition and Aggregation

To assemble behaviors from other classes
HDFC        BoA       Citibank




       CommunicationUtils
30 min Exercise

     Design an OO parking lot. What classes and
     functions will it have. It should say, full, empty
     and also be able to find spot for Valet parking.
     The lot has 3 different types of parking: regular,
     handicapped and compact.
OOPs Development with Scala

Weitere ähnliche Inhalte

Andere mochten auch

Exclusive holiday hideaway appartment in Klosters for weekly lease
Exclusive holiday hideaway appartment in Klosters for weekly leaseExclusive holiday hideaway appartment in Klosters for weekly lease
Exclusive holiday hideaway appartment in Klosters for weekly leaseBeatDolder
 
Årsberetning Destinasjon Trysil BA 2009
Årsberetning Destinasjon Trysil BA 2009Årsberetning Destinasjon Trysil BA 2009
Årsberetning Destinasjon Trysil BA 2009Destinasjon Trysil
 
Effective Data Testing NPT for Final
Effective Data Testing NPT for FinalEffective Data Testing NPT for Final
Effective Data Testing NPT for FinalScott Brackin
 
Yeraldo coraspe t1
Yeraldo coraspe t1Yeraldo coraspe t1
Yeraldo coraspe t1YCoraspe
 
Healthy seedlings_manual
Healthy seedlings_manualHealthy seedlings_manual
Healthy seedlings_manualBharathi P V L
 
Registro de incidencia y mortalidad en pacientes con cáncer (RIMCAN): Informe...
Registro de incidencia y mortalidad en pacientes con cáncer (RIMCAN): Informe...Registro de incidencia y mortalidad en pacientes con cáncer (RIMCAN): Informe...
Registro de incidencia y mortalidad en pacientes con cáncer (RIMCAN): Informe...Alberto Cuadrado
 
Práctica 1 jonathan moreno
Práctica 1 jonathan morenoPráctica 1 jonathan moreno
Práctica 1 jonathan morenojhonrmp
 
Hays world 0214 vertrauen
Hays world 0214 vertrauenHays world 0214 vertrauen
Hays world 0214 vertrauenahoecker
 
Alcheringa ,Sponsership brochure 2011
Alcheringa ,Sponsership  brochure 2011Alcheringa ,Sponsership  brochure 2011
Alcheringa ,Sponsership brochure 2011Prem Kumar Vislawath
 
La importancia de la web 2.0
La importancia de la web 2.0La importancia de la web 2.0
La importancia de la web 2.0Dny colimba
 
TCI2013 The evolution of a tourist cluster in an urban area: the case of Fort...
TCI2013 The evolution of a tourist cluster in an urban area: the case of Fort...TCI2013 The evolution of a tourist cluster in an urban area: the case of Fort...
TCI2013 The evolution of a tourist cluster in an urban area: the case of Fort...TCI Network
 
Fifo pmp
Fifo pmpFifo pmp
Fifo pmpgrijota
 
El aire, el viento y la arquitectura
El aire, el viento y la arquitecturaEl aire, el viento y la arquitectura
El aire, el viento y la arquitecturatici10paulinap
 
Análisis del lenguaje y contenido emocional en #15m en Twitter
Análisis del lenguaje y contenido emocional en #15m en TwitterAnálisis del lenguaje y contenido emocional en #15m en Twitter
Análisis del lenguaje y contenido emocional en #15m en TwitterOutliers Collective
 
Scala traits aug24-introduction
Scala traits aug24-introductionScala traits aug24-introduction
Scala traits aug24-introductionKnoldus Inc.
 

Andere mochten auch (20)

Exclusive holiday hideaway appartment in Klosters for weekly lease
Exclusive holiday hideaway appartment in Klosters for weekly leaseExclusive holiday hideaway appartment in Klosters for weekly lease
Exclusive holiday hideaway appartment in Klosters for weekly lease
 
Årsberetning Destinasjon Trysil BA 2009
Årsberetning Destinasjon Trysil BA 2009Årsberetning Destinasjon Trysil BA 2009
Årsberetning Destinasjon Trysil BA 2009
 
Mi biografia
Mi biografiaMi biografia
Mi biografia
 
Effective Data Testing NPT for Final
Effective Data Testing NPT for FinalEffective Data Testing NPT for Final
Effective Data Testing NPT for Final
 
Yeraldo coraspe t1
Yeraldo coraspe t1Yeraldo coraspe t1
Yeraldo coraspe t1
 
Hearst Elementary School - Update & Modernization Timeline
Hearst Elementary School - Update & Modernization TimelineHearst Elementary School - Update & Modernization Timeline
Hearst Elementary School - Update & Modernization Timeline
 
Healthy seedlings_manual
Healthy seedlings_manualHealthy seedlings_manual
Healthy seedlings_manual
 
Registro de incidencia y mortalidad en pacientes con cáncer (RIMCAN): Informe...
Registro de incidencia y mortalidad en pacientes con cáncer (RIMCAN): Informe...Registro de incidencia y mortalidad en pacientes con cáncer (RIMCAN): Informe...
Registro de incidencia y mortalidad en pacientes con cáncer (RIMCAN): Informe...
 
Práctica 1 jonathan moreno
Práctica 1 jonathan morenoPráctica 1 jonathan moreno
Práctica 1 jonathan moreno
 
Hays world 0214 vertrauen
Hays world 0214 vertrauenHays world 0214 vertrauen
Hays world 0214 vertrauen
 
Alcheringa ,Sponsership brochure 2011
Alcheringa ,Sponsership  brochure 2011Alcheringa ,Sponsership  brochure 2011
Alcheringa ,Sponsership brochure 2011
 
La importancia de la web 2.0
La importancia de la web 2.0La importancia de la web 2.0
La importancia de la web 2.0
 
TCI2013 The evolution of a tourist cluster in an urban area: the case of Fort...
TCI2013 The evolution of a tourist cluster in an urban area: the case of Fort...TCI2013 The evolution of a tourist cluster in an urban area: the case of Fort...
TCI2013 The evolution of a tourist cluster in an urban area: the case of Fort...
 
Fifo pmp
Fifo pmpFifo pmp
Fifo pmp
 
H31110
H31110H31110
H31110
 
DERECHO CIVIL OBLIGACIONES VI
DERECHO CIVIL OBLIGACIONES VIDERECHO CIVIL OBLIGACIONES VI
DERECHO CIVIL OBLIGACIONES VI
 
El aire, el viento y la arquitectura
El aire, el viento y la arquitecturaEl aire, el viento y la arquitectura
El aire, el viento y la arquitectura
 
Análisis del lenguaje y contenido emocional en #15m en Twitter
Análisis del lenguaje y contenido emocional en #15m en TwitterAnálisis del lenguaje y contenido emocional en #15m en Twitter
Análisis del lenguaje y contenido emocional en #15m en Twitter
 
Scala style-guide
Scala style-guideScala style-guide
Scala style-guide
 
Scala traits aug24-introduction
Scala traits aug24-introductionScala traits aug24-introduction
Scala traits aug24-introduction
 

Ähnlich wie OOPs Development with Scala

Things to think about while architecting azure solutions
Things to think about while architecting azure solutionsThings to think about while architecting azure solutions
Things to think about while architecting azure solutionsArnon Rotem-Gal-Oz
 
Evolutionary Systems - Kafka Microservices
Evolutionary Systems - Kafka MicroservicesEvolutionary Systems - Kafka Microservices
Evolutionary Systems - Kafka MicroservicesStefano Rocco
 
The use of Symfony2 @ Overblog
The use of Symfony2 @ OverblogThe use of Symfony2 @ Overblog
The use of Symfony2 @ OverblogXavier Hausherr
 
MongoDB.local Atlanta: Introduction to Serverless MongoDB
MongoDB.local Atlanta: Introduction to Serverless MongoDBMongoDB.local Atlanta: Introduction to Serverless MongoDB
MongoDB.local Atlanta: Introduction to Serverless MongoDBMongoDB
 
BlackHat EU 2012 - Zhenhua Liu - Breeding Sandworms: How To Fuzz Your Way Out...
BlackHat EU 2012 - Zhenhua Liu - Breeding Sandworms: How To Fuzz Your Way Out...BlackHat EU 2012 - Zhenhua Liu - Breeding Sandworms: How To Fuzz Your Way Out...
BlackHat EU 2012 - Zhenhua Liu - Breeding Sandworms: How To Fuzz Your Way Out...MindShare_kk
 
The Art of Message Queues
The Art of Message QueuesThe Art of Message Queues
The Art of Message QueuesMike Willbanks
 
No More Hops Towards A Linearly Scalable Application Infrastructure
No More Hops Towards A Linearly Scalable Application InfrastructureNo More Hops Towards A Linearly Scalable Application Infrastructure
No More Hops Towards A Linearly Scalable Application InfrastructureConSanFrancisco123
 
Reactive microserviceinaction
Reactive microserviceinactionReactive microserviceinaction
Reactive microserviceinactionEmily Jiang
 
Slash n: Tech Talk Track 2 – Distributed Transactions in SOA - Yogi Kulkarni,...
Slash n: Tech Talk Track 2 – Distributed Transactions in SOA - Yogi Kulkarni,...Slash n: Tech Talk Track 2 – Distributed Transactions in SOA - Yogi Kulkarni,...
Slash n: Tech Talk Track 2 – Distributed Transactions in SOA - Yogi Kulkarni,...slashn
 
Reactive Microservice With MicroProfile | Community Day, EclipseCon Europe 2019
Reactive Microservice With MicroProfile | Community Day, EclipseCon Europe 2019Reactive Microservice With MicroProfile | Community Day, EclipseCon Europe 2019
Reactive Microservice With MicroProfile | Community Day, EclipseCon Europe 2019Jakarta_EE
 
The container ecosystem @ Microsoft A story of developer productivity
The container ecosystem @ MicrosoftA story of developer productivityThe container ecosystem @ MicrosoftA story of developer productivity
The container ecosystem @ Microsoft A story of developer productivityNills Franssens
 
2010 06-24 karlsruher entwicklertag
2010 06-24 karlsruher entwicklertag2010 06-24 karlsruher entwicklertag
2010 06-24 karlsruher entwicklertagMarcel Bruch
 
[CB21] ProxyLogon is Just the Tip of the Iceberg, A New Attack Surface on Mic...
[CB21] ProxyLogon is Just the Tip of the Iceberg, A New Attack Surface on Mic...[CB21] ProxyLogon is Just the Tip of the Iceberg, A New Attack Surface on Mic...
[CB21] ProxyLogon is Just the Tip of the Iceberg, A New Attack Surface on Mic...CODE BLUE
 
Reactive microserviceinaction@devnexus
Reactive microserviceinaction@devnexusReactive microserviceinaction@devnexus
Reactive microserviceinaction@devnexusEmily Jiang
 
Konsistenz-in-verteilten-Systemen-leichtgemacht.pdf
Konsistenz-in-verteilten-Systemen-leichtgemacht.pdfKonsistenz-in-verteilten-Systemen-leichtgemacht.pdf
Konsistenz-in-verteilten-Systemen-leichtgemacht.pdfSusanne Braun
 

Ähnlich wie OOPs Development with Scala (20)

Things to think about while architecting azure solutions
Things to think about while architecting azure solutionsThings to think about while architecting azure solutions
Things to think about while architecting azure solutions
 
Evolutionary Systems - Kafka Microservices
Evolutionary Systems - Kafka MicroservicesEvolutionary Systems - Kafka Microservices
Evolutionary Systems - Kafka Microservices
 
The use of Symfony2 @ Overblog
The use of Symfony2 @ OverblogThe use of Symfony2 @ Overblog
The use of Symfony2 @ Overblog
 
MongoDB.local Atlanta: Introduction to Serverless MongoDB
MongoDB.local Atlanta: Introduction to Serverless MongoDBMongoDB.local Atlanta: Introduction to Serverless MongoDB
MongoDB.local Atlanta: Introduction to Serverless MongoDB
 
Jatin_Resume
Jatin_ResumeJatin_Resume
Jatin_Resume
 
BlackHat EU 2012 - Zhenhua Liu - Breeding Sandworms: How To Fuzz Your Way Out...
BlackHat EU 2012 - Zhenhua Liu - Breeding Sandworms: How To Fuzz Your Way Out...BlackHat EU 2012 - Zhenhua Liu - Breeding Sandworms: How To Fuzz Your Way Out...
BlackHat EU 2012 - Zhenhua Liu - Breeding Sandworms: How To Fuzz Your Way Out...
 
The Art of Message Queues
The Art of Message QueuesThe Art of Message Queues
The Art of Message Queues
 
No More Hops Towards A Linearly Scalable Application Infrastructure
No More Hops Towards A Linearly Scalable Application InfrastructureNo More Hops Towards A Linearly Scalable Application Infrastructure
No More Hops Towards A Linearly Scalable Application Infrastructure
 
Reactive microserviceinaction
Reactive microserviceinactionReactive microserviceinaction
Reactive microserviceinaction
 
Slash n: Tech Talk Track 2 – Distributed Transactions in SOA - Yogi Kulkarni,...
Slash n: Tech Talk Track 2 – Distributed Transactions in SOA - Yogi Kulkarni,...Slash n: Tech Talk Track 2 – Distributed Transactions in SOA - Yogi Kulkarni,...
Slash n: Tech Talk Track 2 – Distributed Transactions in SOA - Yogi Kulkarni,...
 
Reactive Microservice With MicroProfile | Community Day, EclipseCon Europe 2019
Reactive Microservice With MicroProfile | Community Day, EclipseCon Europe 2019Reactive Microservice With MicroProfile | Community Day, EclipseCon Europe 2019
Reactive Microservice With MicroProfile | Community Day, EclipseCon Europe 2019
 
The container ecosystem @ Microsoft A story of developer productivity
The container ecosystem @ MicrosoftA story of developer productivityThe container ecosystem @ MicrosoftA story of developer productivity
The container ecosystem @ Microsoft A story of developer productivity
 
2010 06-24 karlsruher entwicklertag
2010 06-24 karlsruher entwicklertag2010 06-24 karlsruher entwicklertag
2010 06-24 karlsruher entwicklertag
 
[CB21] ProxyLogon is Just the Tip of the Iceberg, A New Attack Surface on Mic...
[CB21] ProxyLogon is Just the Tip of the Iceberg, A New Attack Surface on Mic...[CB21] ProxyLogon is Just the Tip of the Iceberg, A New Attack Surface on Mic...
[CB21] ProxyLogon is Just the Tip of the Iceberg, A New Attack Surface on Mic...
 
Continuous Integration & the Release Maturity Model
Continuous Integration & the Release Maturity Model Continuous Integration & the Release Maturity Model
Continuous Integration & the Release Maturity Model
 
Reactive microserviceinaction@devnexus
Reactive microserviceinaction@devnexusReactive microserviceinaction@devnexus
Reactive microserviceinaction@devnexus
 
Dependency Injection Styles
Dependency Injection StylesDependency Injection Styles
Dependency Injection Styles
 
Konsistenz-in-verteilten-Systemen-leichtgemacht.pdf
Konsistenz-in-verteilten-Systemen-leichtgemacht.pdfKonsistenz-in-verteilten-Systemen-leichtgemacht.pdf
Konsistenz-in-verteilten-Systemen-leichtgemacht.pdf
 
Lets focus on business value
Lets focus on business valueLets focus on business value
Lets focus on business value
 
Lets focus on business value
Lets focus on business valueLets focus on business value
Lets focus on business value
 

Mehr von Knoldus Inc.

Mastering Web Scraping with JSoup Unlocking the Secrets of HTML Parsing
Mastering Web Scraping with JSoup Unlocking the Secrets of HTML ParsingMastering Web Scraping with JSoup Unlocking the Secrets of HTML Parsing
Mastering Web Scraping with JSoup Unlocking the Secrets of HTML ParsingKnoldus Inc.
 
Akka gRPC Essentials A Hands-On Introduction
Akka gRPC Essentials A Hands-On IntroductionAkka gRPC Essentials A Hands-On Introduction
Akka gRPC Essentials A Hands-On IntroductionKnoldus Inc.
 
Entity Core with Core Microservices.pptx
Entity Core with Core Microservices.pptxEntity Core with Core Microservices.pptx
Entity Core with Core Microservices.pptxKnoldus Inc.
 
Introduction to Redis and its features.pptx
Introduction to Redis and its features.pptxIntroduction to Redis and its features.pptx
Introduction to Redis and its features.pptxKnoldus Inc.
 
GraphQL with .NET Core Microservices.pdf
GraphQL with .NET Core Microservices.pdfGraphQL with .NET Core Microservices.pdf
GraphQL with .NET Core Microservices.pdfKnoldus Inc.
 
NuGet Packages Presentation (DoT NeT).pptx
NuGet Packages Presentation (DoT NeT).pptxNuGet Packages Presentation (DoT NeT).pptx
NuGet Packages Presentation (DoT NeT).pptxKnoldus Inc.
 
Data Quality in Test Automation Navigating the Path to Reliable Testing
Data Quality in Test Automation Navigating the Path to Reliable TestingData Quality in Test Automation Navigating the Path to Reliable Testing
Data Quality in Test Automation Navigating the Path to Reliable TestingKnoldus Inc.
 
K8sGPTThe AI​ way to diagnose Kubernetes
K8sGPTThe AI​ way to diagnose KubernetesK8sGPTThe AI​ way to diagnose Kubernetes
K8sGPTThe AI​ way to diagnose KubernetesKnoldus Inc.
 
Introduction to Circle Ci Presentation.pptx
Introduction to Circle Ci Presentation.pptxIntroduction to Circle Ci Presentation.pptx
Introduction to Circle Ci Presentation.pptxKnoldus Inc.
 
Robusta -Tool Presentation (DevOps).pptx
Robusta -Tool Presentation (DevOps).pptxRobusta -Tool Presentation (DevOps).pptx
Robusta -Tool Presentation (DevOps).pptxKnoldus Inc.
 
Optimizing Kubernetes using GOLDILOCKS.pptx
Optimizing Kubernetes using GOLDILOCKS.pptxOptimizing Kubernetes using GOLDILOCKS.pptx
Optimizing Kubernetes using GOLDILOCKS.pptxKnoldus Inc.
 
Azure Function App Exception Handling.pptx
Azure Function App Exception Handling.pptxAzure Function App Exception Handling.pptx
Azure Function App Exception Handling.pptxKnoldus Inc.
 
CQRS Design Pattern Presentation (Java).pptx
CQRS Design Pattern Presentation (Java).pptxCQRS Design Pattern Presentation (Java).pptx
CQRS Design Pattern Presentation (Java).pptxKnoldus Inc.
 
ETL Observability: Azure to Snowflake Presentation
ETL Observability: Azure to Snowflake PresentationETL Observability: Azure to Snowflake Presentation
ETL Observability: Azure to Snowflake PresentationKnoldus Inc.
 
Scripting with K6 - Beyond the Basics Presentation
Scripting with K6 - Beyond the Basics PresentationScripting with K6 - Beyond the Basics Presentation
Scripting with K6 - Beyond the Basics PresentationKnoldus Inc.
 
Getting started with dotnet core Web APIs
Getting started with dotnet core Web APIsGetting started with dotnet core Web APIs
Getting started with dotnet core Web APIsKnoldus Inc.
 
Introduction To Rust part II Presentation
Introduction To Rust part II PresentationIntroduction To Rust part II Presentation
Introduction To Rust part II PresentationKnoldus Inc.
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationKnoldus Inc.
 
Configuring Workflows & Validators in JIRA
Configuring Workflows & Validators in JIRAConfiguring Workflows & Validators in JIRA
Configuring Workflows & Validators in JIRAKnoldus Inc.
 
Advanced Python (with dependency injection and hydra configuration packages)
Advanced Python (with dependency injection and hydra configuration packages)Advanced Python (with dependency injection and hydra configuration packages)
Advanced Python (with dependency injection and hydra configuration packages)Knoldus Inc.
 

Mehr von Knoldus Inc. (20)

Mastering Web Scraping with JSoup Unlocking the Secrets of HTML Parsing
Mastering Web Scraping with JSoup Unlocking the Secrets of HTML ParsingMastering Web Scraping with JSoup Unlocking the Secrets of HTML Parsing
Mastering Web Scraping with JSoup Unlocking the Secrets of HTML Parsing
 
Akka gRPC Essentials A Hands-On Introduction
Akka gRPC Essentials A Hands-On IntroductionAkka gRPC Essentials A Hands-On Introduction
Akka gRPC Essentials A Hands-On Introduction
 
Entity Core with Core Microservices.pptx
Entity Core with Core Microservices.pptxEntity Core with Core Microservices.pptx
Entity Core with Core Microservices.pptx
 
Introduction to Redis and its features.pptx
Introduction to Redis and its features.pptxIntroduction to Redis and its features.pptx
Introduction to Redis and its features.pptx
 
GraphQL with .NET Core Microservices.pdf
GraphQL with .NET Core Microservices.pdfGraphQL with .NET Core Microservices.pdf
GraphQL with .NET Core Microservices.pdf
 
NuGet Packages Presentation (DoT NeT).pptx
NuGet Packages Presentation (DoT NeT).pptxNuGet Packages Presentation (DoT NeT).pptx
NuGet Packages Presentation (DoT NeT).pptx
 
Data Quality in Test Automation Navigating the Path to Reliable Testing
Data Quality in Test Automation Navigating the Path to Reliable TestingData Quality in Test Automation Navigating the Path to Reliable Testing
Data Quality in Test Automation Navigating the Path to Reliable Testing
 
K8sGPTThe AI​ way to diagnose Kubernetes
K8sGPTThe AI​ way to diagnose KubernetesK8sGPTThe AI​ way to diagnose Kubernetes
K8sGPTThe AI​ way to diagnose Kubernetes
 
Introduction to Circle Ci Presentation.pptx
Introduction to Circle Ci Presentation.pptxIntroduction to Circle Ci Presentation.pptx
Introduction to Circle Ci Presentation.pptx
 
Robusta -Tool Presentation (DevOps).pptx
Robusta -Tool Presentation (DevOps).pptxRobusta -Tool Presentation (DevOps).pptx
Robusta -Tool Presentation (DevOps).pptx
 
Optimizing Kubernetes using GOLDILOCKS.pptx
Optimizing Kubernetes using GOLDILOCKS.pptxOptimizing Kubernetes using GOLDILOCKS.pptx
Optimizing Kubernetes using GOLDILOCKS.pptx
 
Azure Function App Exception Handling.pptx
Azure Function App Exception Handling.pptxAzure Function App Exception Handling.pptx
Azure Function App Exception Handling.pptx
 
CQRS Design Pattern Presentation (Java).pptx
CQRS Design Pattern Presentation (Java).pptxCQRS Design Pattern Presentation (Java).pptx
CQRS Design Pattern Presentation (Java).pptx
 
ETL Observability: Azure to Snowflake Presentation
ETL Observability: Azure to Snowflake PresentationETL Observability: Azure to Snowflake Presentation
ETL Observability: Azure to Snowflake Presentation
 
Scripting with K6 - Beyond the Basics Presentation
Scripting with K6 - Beyond the Basics PresentationScripting with K6 - Beyond the Basics Presentation
Scripting with K6 - Beyond the Basics Presentation
 
Getting started with dotnet core Web APIs
Getting started with dotnet core Web APIsGetting started with dotnet core Web APIs
Getting started with dotnet core Web APIs
 
Introduction To Rust part II Presentation
Introduction To Rust part II PresentationIntroduction To Rust part II Presentation
Introduction To Rust part II Presentation
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog Presentation
 
Configuring Workflows & Validators in JIRA
Configuring Workflows & Validators in JIRAConfiguring Workflows & Validators in JIRA
Configuring Workflows & Validators in JIRA
 
Advanced Python (with dependency injection and hydra configuration packages)
Advanced Python (with dependency injection and hydra configuration packages)Advanced Python (with dependency injection and hydra configuration packages)
Advanced Python (with dependency injection and hydra configuration packages)
 

Kürzlich hochgeladen

The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
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
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
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
 
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
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
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
 
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
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
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
 
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
 
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
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 

Kürzlich hochgeladen (20)

The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
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
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
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
 
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...
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
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
 
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
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
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
 
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
 
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
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 

OOPs Development with Scala

  • 1. Introduction to Object Oriented Programming Mumbai
  • 2. What is an object? Dog Snowy
  • 3. Dog is a generalization of Snowy Dog Animal Snowy Subclass?
  • 4. Dog Animal Bird Polymorphism?
  • 5. object Real world abstractions Encapsulate state represent information state Communicate by Message passing behavior May execute in sequence Or in parallel
  • 6. name state behavior
  • 7. inheritance encapsulation Building blocks polymorphism
  • 8. Inheritance lets you build classes based on other classes, thus avoiding duplicating and repeating code
  • 9. When a class inherits from another, Polymorphism allows a subclass to standin for a superclass duck cuckoo Bird.flapWings() ostrich
  • 10. Encapsulation is to hide the internal representation of the object from view outside object definition Car.drive() Car drive()
  • 11. camry car accord Vehicle toyota motorcycle honda Harley-davidson civic corolla 5 mins
  • 13. What the stakeholders want 1 Add flexibility, Remove duplication Encapsulation, 2 Inheritance, Polymorphism 3 Apply patterns Loose coupling Delegation
  • 14. We have a product which collects checks from various banks and processes them. The process includes sending out email, a fax or storing a scan for the check.
  • 15. Pay attention to the nouns (person, place or thing) they are object candidates The verbs would be the possible methods This is called textual analysis
  • 16. We have a product which collects checks from various banks and processes them. The process includes sending out email, a fax or storing a scan for the check. 5 mins
  • 17. We have a product which collects checks from various banks and processes them. The process includes sending out email, a fax or storing a scan for the check.
  • 18. FastProcessor process(check:Check) Bank sendEmail(check:Check) sendFax(check:Check) scan(check:Check) * Check ---------------- bank:Bank
  • 20. case class Bank(id:Int, name:String) case class Check(number:Int, bank:Bank) class FastProcessor { def process(checks:List[Check]) = checks foreach (check => sendEmail) def sendEmail = println("Email sent") } val citibank = new Bank(1, "Citibank") //> citibank : com.baml.ooad.Bank = Bank(1,Citibank) (new FastProcessor).process(List(new Check(1,citibank), new Check(2,citibank))) //> Email sent //| Email sent
  • 21. We need to support BoA as well and that sends Faxes
  • 22. We dont touch the design
  • 23. case class Bank(id:Int, name:String) case class Check(number:Int, bank:Bank) class FastProcessor { def process(checks:List[Check]) = checks foreach (check => if (check.bank.name=="Citibank") sendEmail else sendFax) def sendEmail = println("Email sent") def sendFax = println("Fax sent") } val citibank = new Bank(1, "Citibank") // val bankOfAmerica = new Bank(2, "BoA") // val citibankCheckList = List(new Check(1,citibank), new Check(2,citibank)) val bankOfAmericaCheckList = List(new Check(1,bankOfAmerica), new Check(2,bankOfAmerica)) (new FastProcessor).process(citibankCheckList ::: bankOfAmericaCheckList) //> Email sent //| Email sent //| Fax sent //| Fax sent
  • 24. We need to support HDFC and ICICI as well now!
  • 25. good design == flexible design whenever there is a change encapsulate it 5 mins
  • 26. What the stakeholders want 1 Add flexibility, Remove duplication Encapsulation, 2 Inheritance, Polymorphism 3 Apply patterns Loose coupling Delegation
  • 27. trait Bank { def process(check: Check) } object CitiBank extends Bank { val name = "CitiBank" def process(check: Check) = sendEmail def sendEmail = println("Email sent") } object BankOfAmerica extends Bank { val name = "BoA" def process(check: Check) = sendFax def sendFax = println("Fax sent") } object HDFC extends Bank { val name = "HDFC" def process(check: Check) = {sendFax; sendEmail} def sendEmail = println("Email sent") def sendFax = println("Fax sent") } case class Check(number: Int, bank: Bank)
  • 28. class FastProcessor { def process(checks: List[Check]) = checks foreach (check => check.bank.process(check)) } val citibankCheckList = List(new Check(1, CitiBank), new Check(2, CitiBank)) val bankOfAmericaCheckList = List(new Check(1, BankOfAmerica), new Check(2, BankOfAmerica)) val hdfcCheckList = List(new Check(1, HDFC)) (new FastProcessor).process(citibankCheckList ::: bankOfAmericaCheckList ::: hdfcCheckList) //> Email sent //| Email sent //| Fax sent //| Fax sent //| Fax sent //| Email sent
  • 29. bank FastProcessor HDFC BoA Citibank Check
  • 30. bank FastProcessor HDFC BoA Citibank Check
  • 31. Code to interfaces – makes software easy to extend Encapsulate what varies – protect classes from changes Each class should have only one reason to change
  • 32. What the stakeholders want 1 Add flexibility, Remove duplication Encapsulation, Inheritance, 2 Polymorphism 3 Apply patterns Loose coupling Delegation
  • 33. OO Principles result in maintenable, flexible and extensible software
  • 34. Open Closed Principle Classes should be open for extension and closed for modification
  • 35. bank HDFC BoA Citibank Any number of banks?
  • 36. DRY Don't repeat yourself All duplicate code should be encapsulated / abstracted
  • 37. bank FastProcessor HDFC BoA Citibank Check CommunicationUtils
  • 38. What the stakeholders want 1 Add flexibility, Remove duplication Encapsulation, Inheritance, 2 Polymorphism 3 Apply patterns Loose coupling Delegation
  • 39. Single Responsibility Principle Each object should have only one reason to change
  • 40.
  • 41. What methods should really belong to Automobile?
  • 42.
  • 43. Liskov Substitution Principle Subtypes MUST be substitutable for their base types Ensures well designed inheritance
  • 45. class Rectangle { var height: Int = 0 var width: Int = 0 def setHeight(h: Int) = { height = h } def setWidth(w: Int) = { width = w } } class Square extends Rectangle { override def setHeight(h: Int) = { height = h; width = h } override def setWidth(w: Int) = { width = w; height = w } } val rectangle = new Square rectangle.setHeight(10) rectangle.setWidth(5) assert(10 == rectangle.height) //> java.lang.AssertionError: assertion failed
  • 46. There are multiple options other than inheritance
  • 47. Delegation When once class hands off the task of doing something to another Useful when you want to use the functionality of another class without changing its behavior
  • 48. bank HDFC BoA Citibank We delegated processing to individual banks
  • 49. Composition and Aggregation To assemble behaviors from other classes
  • 50. HDFC BoA Citibank CommunicationUtils
  • 51. 30 min Exercise Design an OO parking lot. What classes and functions will it have. It should say, full, empty and also be able to find spot for Valet parking. The lot has 3 different types of parking: regular, handicapped and compact.