尊敬的 微信汇率:1円 ≈ 0.046078 元 支付宝汇率:1円 ≈ 0.046168元 [退出登录]
SlideShare a Scribd company logo
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

More Related Content

Viewers also liked

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
BeatDolder
 
Årsberetning Destinasjon Trysil BA 2009
Årsberetning Destinasjon Trysil BA 2009Årsberetning Destinasjon Trysil BA 2009
Årsberetning Destinasjon Trysil BA 2009Destinasjon Trysil
 
Mi biografia
Mi biografiaMi biografia
Mi biografia
Andrea0829
 
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
 
Hearst Elementary School - Update & Modernization Timeline
Hearst Elementary School - Update & Modernization TimelineHearst Elementary School - Update & Modernization Timeline
Hearst Elementary School - Update & Modernization Timeline
DC Department of General Services
 
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 vertrauenahoecker
 
Alcheringa ,Sponsership brochure 2011
Alcheringa ,Sponsership  brochure 2011Alcheringa ,Sponsership  brochure 2011
Alcheringa ,Sponsership brochure 2011
Prem 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.0
Dny 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 pmp
grijota
 
DERECHO CIVIL OBLIGACIONES VI
DERECHO CIVIL OBLIGACIONES VIDERECHO CIVIL OBLIGACIONES VI
DERECHO CIVIL OBLIGACIONES VI
Jhon Mamani Condori
 
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
 
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
Outliers Collective
 
Scala style-guide
Scala style-guideScala style-guide
Scala style-guide
Knoldus Inc.
 
Scala traits aug24-introduction
Scala traits aug24-introductionScala traits aug24-introduction
Scala traits aug24-introduction
Knoldus Inc.
 

Viewers also liked (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
 

Similar to 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
 
Evolutionary Systems - Kafka Microservices
Evolutionary Systems - Kafka MicroservicesEvolutionary Systems - Kafka Microservices
Evolutionary Systems - Kafka Microservices
Stefano Rocco
 
The use of Symfony2 @ Overblog
The use of Symfony2 @ OverblogThe use of Symfony2 @ Overblog
The use of Symfony2 @ Overblog
Xavier 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 MongoDB
MongoDB
 
Jatin_Resume
Jatin_ResumeJatin_Resume
Jatin_Resume
Jatin Nahar
 
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 Queues
Mike 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 Infrastructure
ConSanFrancisco123
 
Reactive microserviceinaction
Reactive microserviceinactionReactive microserviceinaction
Reactive microserviceinaction
Emily 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 2019
Jakarta_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 productivity
Nills Franssens
 
2010 06-24 karlsruher entwicklertag
2010 06-24 karlsruher entwicklertag2010 06-24 karlsruher entwicklertag
2010 06-24 karlsruher entwicklertag
Marcel Bruch
 
Introduction-to-Service-Mesh-with-Istio-and-Kiali-OSS-Japan-July-2019.pdf
Introduction-to-Service-Mesh-with-Istio-and-Kiali-OSS-Japan-July-2019.pdfIntroduction-to-Service-Mesh-with-Istio-and-Kiali-OSS-Japan-July-2019.pdf
Introduction-to-Service-Mesh-with-Istio-and-Kiali-OSS-Japan-July-2019.pdf
ALVAROEMMANUELSOCOPP
 
[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
 
Continuous Integration & the Release Maturity Model
Continuous Integration & the Release Maturity Model Continuous Integration & the Release Maturity Model
Continuous Integration & the Release Maturity Model
cPrime | Project Management | Agile | Consulting | Staffing | Training
 
Reactive microserviceinaction@devnexus
Reactive microserviceinaction@devnexusReactive microserviceinaction@devnexus
Reactive microserviceinaction@devnexus
Emily Jiang
 
Dependency Injection Styles
Dependency Injection StylesDependency Injection Styles
Dependency Injection Styles
Spring User Group France
 
Konsistenz-in-verteilten-Systemen-leichtgemacht.pdf
Konsistenz-in-verteilten-Systemen-leichtgemacht.pdfKonsistenz-in-verteilten-Systemen-leichtgemacht.pdf
Konsistenz-in-verteilten-Systemen-leichtgemacht.pdf
Susanne Braun
 
Lets focus on business value
Lets focus on business valueLets focus on business value
Lets focus on business value
Einar Ingebrigtsen
 

Similar to 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
 
Introduction-to-Service-Mesh-with-Istio-and-Kiali-OSS-Japan-July-2019.pdf
Introduction-to-Service-Mesh-with-Istio-and-Kiali-OSS-Japan-July-2019.pdfIntroduction-to-Service-Mesh-with-Istio-and-Kiali-OSS-Japan-July-2019.pdf
Introduction-to-Service-Mesh-with-Istio-and-Kiali-OSS-Japan-July-2019.pdf
 
[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
 

More from Knoldus Inc.

Insights Unveiled Test Reporting and Observability Excellence
Insights Unveiled Test Reporting and Observability ExcellenceInsights Unveiled Test Reporting and Observability Excellence
Insights Unveiled Test Reporting and Observability Excellence
Knoldus Inc.
 
Introduction to Splunk Presentation (DevOps)
Introduction to Splunk Presentation (DevOps)Introduction to Splunk Presentation (DevOps)
Introduction to Splunk Presentation (DevOps)
Knoldus Inc.
 
Code Camp - Data Profiling and Quality Analysis Framework
Code Camp - Data Profiling and Quality Analysis FrameworkCode Camp - Data Profiling and Quality Analysis Framework
Code Camp - Data Profiling and Quality Analysis Framework
Knoldus Inc.
 
AWS: Messaging Services in AWS Presentation
AWS: Messaging Services in AWS PresentationAWS: Messaging Services in AWS Presentation
AWS: Messaging Services in AWS Presentation
Knoldus Inc.
 
Amazon Cognito: A Primer on Authentication and Authorization
Amazon Cognito: A Primer on Authentication and AuthorizationAmazon Cognito: A Primer on Authentication and Authorization
Amazon Cognito: A Primer on Authentication and Authorization
Knoldus Inc.
 
ZIO Http A Functional Approach to Scalable and Type-Safe Web Development
ZIO Http A Functional Approach to Scalable and Type-Safe Web DevelopmentZIO Http A Functional Approach to Scalable and Type-Safe Web Development
ZIO Http A Functional Approach to Scalable and Type-Safe Web Development
Knoldus Inc.
 
Managing State & HTTP Requests In Ionic.
Managing State & HTTP Requests In Ionic.Managing State & HTTP Requests In Ionic.
Managing State & HTTP Requests In Ionic.
Knoldus Inc.
 
Facilitation Skills - When to Use and Why.pptx
Facilitation Skills - When to Use and Why.pptxFacilitation Skills - When to Use and Why.pptx
Facilitation Skills - When to Use and Why.pptx
Knoldus Inc.
 
Performance Testing at Scale Techniques for High-Volume Services
Performance Testing at Scale Techniques for High-Volume ServicesPerformance Testing at Scale Techniques for High-Volume Services
Performance Testing at Scale Techniques for High-Volume Services
Knoldus Inc.
 
Snowflake and its features (Presentation)
Snowflake and its features (Presentation)Snowflake and its features (Presentation)
Snowflake and its features (Presentation)
Knoldus Inc.
 
Terratest - Automation testing of infrastructure
Terratest - Automation testing of infrastructureTerratest - Automation testing of infrastructure
Terratest - Automation testing of infrastructure
Knoldus Inc.
 
Getting Started with Apache Spark (Scala)
Getting Started with Apache Spark (Scala)Getting Started with Apache Spark (Scala)
Getting Started with Apache Spark (Scala)
Knoldus Inc.
 
Secure practices with dot net services.pptx
Secure practices with dot net services.pptxSecure practices with dot net services.pptx
Secure practices with dot net services.pptx
Knoldus Inc.
 
Distributed Cache with dot microservices
Distributed Cache with dot microservicesDistributed Cache with dot microservices
Distributed Cache with dot microservices
Knoldus Inc.
 
Introduction to gRPC Presentation (Java)
Introduction to gRPC Presentation (Java)Introduction to gRPC Presentation (Java)
Introduction to gRPC Presentation (Java)
Knoldus Inc.
 
Using InfluxDB for real-time monitoring in Jmeter
Using InfluxDB for real-time monitoring in JmeterUsing InfluxDB for real-time monitoring in Jmeter
Using InfluxDB for real-time monitoring in Jmeter
Knoldus Inc.
 
Intoduction to KubeVela Presentation (DevOps)
Intoduction to KubeVela Presentation (DevOps)Intoduction to KubeVela Presentation (DevOps)
Intoduction to KubeVela Presentation (DevOps)
Knoldus Inc.
 
Stakeholder Management (Project Management) Presentation
Stakeholder Management (Project Management) PresentationStakeholder Management (Project Management) Presentation
Stakeholder Management (Project Management) Presentation
Knoldus Inc.
 
Introduction To Kaniko (DevOps) Presentation
Introduction To Kaniko (DevOps) PresentationIntroduction To Kaniko (DevOps) Presentation
Introduction To Kaniko (DevOps) Presentation
Knoldus Inc.
 
Efficient Test Environments with Infrastructure as Code (IaC)
Efficient Test Environments with Infrastructure as Code (IaC)Efficient Test Environments with Infrastructure as Code (IaC)
Efficient Test Environments with Infrastructure as Code (IaC)
Knoldus Inc.
 

More from Knoldus Inc. (20)

Insights Unveiled Test Reporting and Observability Excellence
Insights Unveiled Test Reporting and Observability ExcellenceInsights Unveiled Test Reporting and Observability Excellence
Insights Unveiled Test Reporting and Observability Excellence
 
Introduction to Splunk Presentation (DevOps)
Introduction to Splunk Presentation (DevOps)Introduction to Splunk Presentation (DevOps)
Introduction to Splunk Presentation (DevOps)
 
Code Camp - Data Profiling and Quality Analysis Framework
Code Camp - Data Profiling and Quality Analysis FrameworkCode Camp - Data Profiling and Quality Analysis Framework
Code Camp - Data Profiling and Quality Analysis Framework
 
AWS: Messaging Services in AWS Presentation
AWS: Messaging Services in AWS PresentationAWS: Messaging Services in AWS Presentation
AWS: Messaging Services in AWS Presentation
 
Amazon Cognito: A Primer on Authentication and Authorization
Amazon Cognito: A Primer on Authentication and AuthorizationAmazon Cognito: A Primer on Authentication and Authorization
Amazon Cognito: A Primer on Authentication and Authorization
 
ZIO Http A Functional Approach to Scalable and Type-Safe Web Development
ZIO Http A Functional Approach to Scalable and Type-Safe Web DevelopmentZIO Http A Functional Approach to Scalable and Type-Safe Web Development
ZIO Http A Functional Approach to Scalable and Type-Safe Web Development
 
Managing State & HTTP Requests In Ionic.
Managing State & HTTP Requests In Ionic.Managing State & HTTP Requests In Ionic.
Managing State & HTTP Requests In Ionic.
 
Facilitation Skills - When to Use and Why.pptx
Facilitation Skills - When to Use and Why.pptxFacilitation Skills - When to Use and Why.pptx
Facilitation Skills - When to Use and Why.pptx
 
Performance Testing at Scale Techniques for High-Volume Services
Performance Testing at Scale Techniques for High-Volume ServicesPerformance Testing at Scale Techniques for High-Volume Services
Performance Testing at Scale Techniques for High-Volume Services
 
Snowflake and its features (Presentation)
Snowflake and its features (Presentation)Snowflake and its features (Presentation)
Snowflake and its features (Presentation)
 
Terratest - Automation testing of infrastructure
Terratest - Automation testing of infrastructureTerratest - Automation testing of infrastructure
Terratest - Automation testing of infrastructure
 
Getting Started with Apache Spark (Scala)
Getting Started with Apache Spark (Scala)Getting Started with Apache Spark (Scala)
Getting Started with Apache Spark (Scala)
 
Secure practices with dot net services.pptx
Secure practices with dot net services.pptxSecure practices with dot net services.pptx
Secure practices with dot net services.pptx
 
Distributed Cache with dot microservices
Distributed Cache with dot microservicesDistributed Cache with dot microservices
Distributed Cache with dot microservices
 
Introduction to gRPC Presentation (Java)
Introduction to gRPC Presentation (Java)Introduction to gRPC Presentation (Java)
Introduction to gRPC Presentation (Java)
 
Using InfluxDB for real-time monitoring in Jmeter
Using InfluxDB for real-time monitoring in JmeterUsing InfluxDB for real-time monitoring in Jmeter
Using InfluxDB for real-time monitoring in Jmeter
 
Intoduction to KubeVela Presentation (DevOps)
Intoduction to KubeVela Presentation (DevOps)Intoduction to KubeVela Presentation (DevOps)
Intoduction to KubeVela Presentation (DevOps)
 
Stakeholder Management (Project Management) Presentation
Stakeholder Management (Project Management) PresentationStakeholder Management (Project Management) Presentation
Stakeholder Management (Project Management) Presentation
 
Introduction To Kaniko (DevOps) Presentation
Introduction To Kaniko (DevOps) PresentationIntroduction To Kaniko (DevOps) Presentation
Introduction To Kaniko (DevOps) Presentation
 
Efficient Test Environments with Infrastructure as Code (IaC)
Efficient Test Environments with Infrastructure as Code (IaC)Efficient Test Environments with Infrastructure as Code (IaC)
Efficient Test Environments with Infrastructure as Code (IaC)
 

Recently uploaded

New ThousandEyes Product Features and Release Highlights: June 2024
New ThousandEyes Product Features and Release Highlights: June 2024New ThousandEyes Product Features and Release Highlights: June 2024
New ThousandEyes Product Features and Release Highlights: June 2024
ThousandEyes
 
ScyllaDB Topology on Raft: An Inside Look
ScyllaDB Topology on Raft: An Inside LookScyllaDB Topology on Raft: An Inside Look
ScyllaDB Topology on Raft: An Inside Look
ScyllaDB
 
Day 2 - Intro to UiPath Studio Fundamentals
Day 2 - Intro to UiPath Studio FundamentalsDay 2 - Intro to UiPath Studio Fundamentals
Day 2 - Intro to UiPath Studio Fundamentals
UiPathCommunity
 
Move Auth, Policy, and Resilience to the Platform
Move Auth, Policy, and Resilience to the PlatformMove Auth, Policy, and Resilience to the Platform
Move Auth, Policy, and Resilience to the Platform
Christian Posta
 
Chapter 6 - Test Tools Considerations V4.0
Chapter 6 - Test Tools Considerations V4.0Chapter 6 - Test Tools Considerations V4.0
Chapter 6 - Test Tools Considerations V4.0
Neeraj Kumar Singh
 
Multivendor cloud production with VSF TR-11 - there and back again
Multivendor cloud production with VSF TR-11 - there and back againMultivendor cloud production with VSF TR-11 - there and back again
Multivendor cloud production with VSF TR-11 - there and back again
Kieran Kunhya
 
The Strategy Behind ReversingLabs’ Massive Key-Value Migration
The Strategy Behind ReversingLabs’ Massive Key-Value MigrationThe Strategy Behind ReversingLabs’ Massive Key-Value Migration
The Strategy Behind ReversingLabs’ Massive Key-Value Migration
ScyllaDB
 
APJC Introduction to ThousandEyes Webinar
APJC Introduction to ThousandEyes WebinarAPJC Introduction to ThousandEyes Webinar
APJC Introduction to ThousandEyes Webinar
ThousandEyes
 
MongoDB vs ScyllaDB: Tractian’s Experience with Real-Time ML
MongoDB vs ScyllaDB: Tractian’s Experience with Real-Time MLMongoDB vs ScyllaDB: Tractian’s Experience with Real-Time ML
MongoDB vs ScyllaDB: Tractian’s Experience with Real-Time ML
ScyllaDB
 
Call Girls Chandigarh🔥7023059433🔥Agency Profile Escorts in Chandigarh Availab...
Call Girls Chandigarh🔥7023059433🔥Agency Profile Escorts in Chandigarh Availab...Call Girls Chandigarh🔥7023059433🔥Agency Profile Escorts in Chandigarh Availab...
Call Girls Chandigarh🔥7023059433🔥Agency Profile Escorts in Chandigarh Availab...
manji sharman06
 
intra-mart Accel series 2024 Spring updates_En
intra-mart Accel series 2024 Spring updates_Enintra-mart Accel series 2024 Spring updates_En
intra-mart Accel series 2024 Spring updates_En
NTTDATA INTRAMART
 
ThousandEyes New Product Features and Release Highlights: June 2024
ThousandEyes New Product Features and Release Highlights: June 2024ThousandEyes New Product Features and Release Highlights: June 2024
ThousandEyes New Product Features and Release Highlights: June 2024
ThousandEyes
 
Call Girls Kochi 💯Call Us 🔝 7426014248 🔝 Independent Kochi Escorts Service Av...
Call Girls Kochi 💯Call Us 🔝 7426014248 🔝 Independent Kochi Escorts Service Av...Call Girls Kochi 💯Call Us 🔝 7426014248 🔝 Independent Kochi Escorts Service Av...
Call Girls Kochi 💯Call Us 🔝 7426014248 🔝 Independent Kochi Escorts Service Av...
dipikamodels1
 
Introduction to ThousandEyes AMER Webinar
Introduction  to ThousandEyes AMER WebinarIntroduction  to ThousandEyes AMER Webinar
Introduction to ThousandEyes AMER Webinar
ThousandEyes
 
Product Listing Optimization Presentation - Gay De La Cruz.pdf
Product Listing Optimization Presentation - Gay De La Cruz.pdfProduct Listing Optimization Presentation - Gay De La Cruz.pdf
Product Listing Optimization Presentation - Gay De La Cruz.pdf
gaydlc2513
 
Communications Mining Series - Zero to Hero - Session 2
Communications Mining Series - Zero to Hero - Session 2Communications Mining Series - Zero to Hero - Session 2
Communications Mining Series - Zero to Hero - Session 2
DianaGray10
 
Radically Outperforming DynamoDB @ Digital Turbine with SADA and Google Cloud
Radically Outperforming DynamoDB @ Digital Turbine with SADA and Google CloudRadically Outperforming DynamoDB @ Digital Turbine with SADA and Google Cloud
Radically Outperforming DynamoDB @ Digital Turbine with SADA and Google Cloud
ScyllaDB
 
Day 4 - Excel Automation and Data Manipulation
Day 4 - Excel Automation and Data ManipulationDay 4 - Excel Automation and Data Manipulation
Day 4 - Excel Automation and Data Manipulation
UiPathCommunity
 
Dev Dives: Mining your data with AI-powered Continuous Discovery
Dev Dives: Mining your data with AI-powered Continuous DiscoveryDev Dives: Mining your data with AI-powered Continuous Discovery
Dev Dives: Mining your data with AI-powered Continuous Discovery
UiPathCommunity
 
Leveraging AI for Software Developer Productivity.pptx
Leveraging AI for Software Developer Productivity.pptxLeveraging AI for Software Developer Productivity.pptx
Leveraging AI for Software Developer Productivity.pptx
petabridge
 

Recently uploaded (20)

New ThousandEyes Product Features and Release Highlights: June 2024
New ThousandEyes Product Features and Release Highlights: June 2024New ThousandEyes Product Features and Release Highlights: June 2024
New ThousandEyes Product Features and Release Highlights: June 2024
 
ScyllaDB Topology on Raft: An Inside Look
ScyllaDB Topology on Raft: An Inside LookScyllaDB Topology on Raft: An Inside Look
ScyllaDB Topology on Raft: An Inside Look
 
Day 2 - Intro to UiPath Studio Fundamentals
Day 2 - Intro to UiPath Studio FundamentalsDay 2 - Intro to UiPath Studio Fundamentals
Day 2 - Intro to UiPath Studio Fundamentals
 
Move Auth, Policy, and Resilience to the Platform
Move Auth, Policy, and Resilience to the PlatformMove Auth, Policy, and Resilience to the Platform
Move Auth, Policy, and Resilience to the Platform
 
Chapter 6 - Test Tools Considerations V4.0
Chapter 6 - Test Tools Considerations V4.0Chapter 6 - Test Tools Considerations V4.0
Chapter 6 - Test Tools Considerations V4.0
 
Multivendor cloud production with VSF TR-11 - there and back again
Multivendor cloud production with VSF TR-11 - there and back againMultivendor cloud production with VSF TR-11 - there and back again
Multivendor cloud production with VSF TR-11 - there and back again
 
The Strategy Behind ReversingLabs’ Massive Key-Value Migration
The Strategy Behind ReversingLabs’ Massive Key-Value MigrationThe Strategy Behind ReversingLabs’ Massive Key-Value Migration
The Strategy Behind ReversingLabs’ Massive Key-Value Migration
 
APJC Introduction to ThousandEyes Webinar
APJC Introduction to ThousandEyes WebinarAPJC Introduction to ThousandEyes Webinar
APJC Introduction to ThousandEyes Webinar
 
MongoDB vs ScyllaDB: Tractian’s Experience with Real-Time ML
MongoDB vs ScyllaDB: Tractian’s Experience with Real-Time MLMongoDB vs ScyllaDB: Tractian’s Experience with Real-Time ML
MongoDB vs ScyllaDB: Tractian’s Experience with Real-Time ML
 
Call Girls Chandigarh🔥7023059433🔥Agency Profile Escorts in Chandigarh Availab...
Call Girls Chandigarh🔥7023059433🔥Agency Profile Escorts in Chandigarh Availab...Call Girls Chandigarh🔥7023059433🔥Agency Profile Escorts in Chandigarh Availab...
Call Girls Chandigarh🔥7023059433🔥Agency Profile Escorts in Chandigarh Availab...
 
intra-mart Accel series 2024 Spring updates_En
intra-mart Accel series 2024 Spring updates_Enintra-mart Accel series 2024 Spring updates_En
intra-mart Accel series 2024 Spring updates_En
 
ThousandEyes New Product Features and Release Highlights: June 2024
ThousandEyes New Product Features and Release Highlights: June 2024ThousandEyes New Product Features and Release Highlights: June 2024
ThousandEyes New Product Features and Release Highlights: June 2024
 
Call Girls Kochi 💯Call Us 🔝 7426014248 🔝 Independent Kochi Escorts Service Av...
Call Girls Kochi 💯Call Us 🔝 7426014248 🔝 Independent Kochi Escorts Service Av...Call Girls Kochi 💯Call Us 🔝 7426014248 🔝 Independent Kochi Escorts Service Av...
Call Girls Kochi 💯Call Us 🔝 7426014248 🔝 Independent Kochi Escorts Service Av...
 
Introduction to ThousandEyes AMER Webinar
Introduction  to ThousandEyes AMER WebinarIntroduction  to ThousandEyes AMER Webinar
Introduction to ThousandEyes AMER Webinar
 
Product Listing Optimization Presentation - Gay De La Cruz.pdf
Product Listing Optimization Presentation - Gay De La Cruz.pdfProduct Listing Optimization Presentation - Gay De La Cruz.pdf
Product Listing Optimization Presentation - Gay De La Cruz.pdf
 
Communications Mining Series - Zero to Hero - Session 2
Communications Mining Series - Zero to Hero - Session 2Communications Mining Series - Zero to Hero - Session 2
Communications Mining Series - Zero to Hero - Session 2
 
Radically Outperforming DynamoDB @ Digital Turbine with SADA and Google Cloud
Radically Outperforming DynamoDB @ Digital Turbine with SADA and Google CloudRadically Outperforming DynamoDB @ Digital Turbine with SADA and Google Cloud
Radically Outperforming DynamoDB @ Digital Turbine with SADA and Google Cloud
 
Day 4 - Excel Automation and Data Manipulation
Day 4 - Excel Automation and Data ManipulationDay 4 - Excel Automation and Data Manipulation
Day 4 - Excel Automation and Data Manipulation
 
Dev Dives: Mining your data with AI-powered Continuous Discovery
Dev Dives: Mining your data with AI-powered Continuous DiscoveryDev Dives: Mining your data with AI-powered Continuous Discovery
Dev Dives: Mining your data with AI-powered Continuous Discovery
 
Leveraging AI for Software Developer Productivity.pptx
Leveraging AI for Software Developer Productivity.pptxLeveraging AI for Software Developer Productivity.pptx
Leveraging AI for Software Developer Productivity.pptx
 

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.
  翻译: