SlideShare uma empresa Scribd logo
1 de 52
Baixar para ler offline
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

Mais conteúdo relacionado

Destaque

Årsberetning Destinasjon Trysil BA 2009
Årsberetning Destinasjon Trysil BA 2009Årsberetning Destinasjon Trysil BA 2009
Årsberetning Destinasjon Trysil BA 2009
Destinasjon Trysil
 
Effective Data Testing NPT for Final
Effective Data Testing NPT for FinalEffective Data Testing NPT for Final
Effective Data Testing NPT for Final
Scott Brackin
 
Yeraldo coraspe t1
Yeraldo coraspe t1Yeraldo coraspe t1
Yeraldo coraspe t1
YCoraspe
 
Healthy seedlings_manual
Healthy seedlings_manualHealthy seedlings_manual
Healthy seedlings_manual
Bharathi 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 moreno
jhonrmp
 
Hays world 0214 vertrauen
Hays world 0214 vertrauenHays world 0214 vertrauen
Hays world 0214 vertrauen
ahoecker
 
Fifo pmp
Fifo pmpFifo pmp
Fifo pmp
grijota
 
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
tici10paulinap
 

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

Semelhante a 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 solutions
Arnon Rotem-Gal-Oz
 
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
ConSanFrancisco123
 
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
 
2010 06-24 karlsruher entwicklertag
2010 06-24 karlsruher entwicklertag2010 06-24 karlsruher entwicklertag
2010 06-24 karlsruher entwicklertag
Marcel 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
 

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

Mais de Knoldus Inc.

Mais de Knoldus Inc. (20)

Supply chain security with Kubeclarity.pptx
Supply chain security with Kubeclarity.pptxSupply chain security with Kubeclarity.pptx
Supply chain security with Kubeclarity.pptx
 
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
 

Último

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
Enterprise Knowledge
 

Último (20)

Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
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
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
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
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
[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
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
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
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
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
 
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
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
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
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 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 🐘
 

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.