SlideShare a Scribd company logo
Cake pattern
1
Alex Fomin
@AlexSane
2
DI IoC
3
DI != IoC
4
DI <: IoC
5
Cake Pattern <: DI
6
Example
7
class ShoppingRobot(listProvider: ShopListProvider, location: GeoLocation) {
def goShopping() = {
val list = listProvider.get
val shop = location.findNearestShop
shop.map(buy(_, list))
}
def buy(shop:Shop, list:List[Item]) = ???
}
class ShopListProvider {
def get:List[Item] = ???
}
class GeoLocation {
def findNearestShop:Maybe[Shop] = ???
}
8
Dependencies
object Application extends App {
val shoplistProvider = new ShopListProvider();
val location = new GeoLocation();
val robot = new ShoppingRobot(shopListProvider, location);
robot.goShopping
}
9
InjectionConstructor
Cake pattern
10
trait ShopListProviderComponent {
val shopListProvider: ShopListProvider
trait ShopListProvider {
def get: List[Item]
}
}
trait GeoLocationComponent {
val geoLocation: GeoLocation
trait GeoLocation {
def findNearestShop: Maybe[Shop]
}
}
11
trait ShoppingRobotComponent {
val robot: ShoppingRobot
trait ShoppingRobot {
def goShopping: Maybe[Purchase]
}
}
trait ShopListProviderComponentImpl extends ShopListProviderComponent {
val shopListProvider: ShopListProvider = new ShopListProviderImpl
class ShopListProviderImpl extends ShopListProvider {
override def get: List[Item] = ???
}
}
trait GeoLocationComponentImpl extends GeoLocationComponent {
val geoLocation: GeoLocation = new GeoLocationImpl
class GeoLocationImpl extends GeoLocation {
override def findNearestShop: Maybe[Shop] = ???
}
}
12
trait ShoppingRobotComponentImpl extends ShoppingRobotComponent {
this: ShoppingRobotComponentImpl
with ShopListProviderComponent
with GeoLocationComponent
=>
val robot: ShoppingRobot = new DefaultRobot
class DefaultRobot extends ShoppingRobot {
override def goShopping: Maybe[Purchase] = {
val list = listProvider.get
val shop = location.findNearestShop
shop.map(buy(_, list))
}
}
}
13
Dependency
object Registry
extends ShoppingRobotComponentImpl
with GeoLocationComponentImpl
with ShopListProviderComponentImpl
object Application extends App {
val robot = Registry.robot
robot.goShopping
}
14
Injection
object FailedRegistry
extends ShoppingRobotComponentImpl
with GeoLocationComponentImpl
error: illegal inheritance;
self-type FailedRegistry.type does not conform to ShoppingRobotComponentImpl's selftype
ShoppingRobotComponentImpl with ShopListProviderComponent with GeoLocationComponent
object FailedRegistry extends ShoppingRobotComponentImpl with
GeoLocationComponentImpl
15
object TestRegistry
extends ShoppingRobotComponentImpl
with FakeGeoLocationComponentImpl
with FakeShopListProviderComponentImpl
class Registry2(shop: Shop)
extends ShoppingRobotComponentImpl
with ShopListProviderComponentImpl
with GeoLocationComponent {
val geoLocation: GeoLocation = new GeoLocation {
override def findNearestShop: Maybe[Shop] = Some(shop)
}
}
16
Pros and Cons
+ Pure Scala
+ Compile time
validation
17
− Boilerplate
overhead
− Weak lifecycle
control
Q&A
18

More Related Content

Viewers also liked

Consumption Pattern and Expenditure
Consumption Pattern and ExpenditureConsumption Pattern and Expenditure
Consumption Pattern and Expendituremandalina landy
 
Работа с Akka Сluster, @afiskon, scalaby#14
Работа с Akka Сluster, @afiskon, scalaby#14Работа с Akka Сluster, @afiskon, scalaby#14
Работа с Akka Сluster, @afiskon, scalaby#14
Vasil Remeniuk
 
Marketing Research Design
Marketing Research DesignMarketing Research Design
Marketing Research Design
Asia Pacific Marketing Institute
 
Effect of Marketing Mix Elements
Effect of Marketing Mix ElementsEffect of Marketing Mix Elements
Effect of Marketing Mix Elements
Fery Darmansyah
 
Presentation Of Research Work
Presentation Of Research WorkPresentation Of Research Work
Presentation Of Research Work
ChandraMouli Gunturi L
 
Research Presentation Format
Research Presentation FormatResearch Presentation Format
Research Presentation Format
Lifelong Learning
 
Research project ppt
Research project pptResearch project ppt
Research project pptJohn McKeown
 
Marketing mix the 7 p's of marketing
Marketing mix  the 7 p's of marketingMarketing mix  the 7 p's of marketing
Marketing mix the 7 p's of marketing
Eli Santos
 
Basic Baking Ingredients and Their Functions
Basic Baking Ingredients and Their FunctionsBasic Baking Ingredients and Their Functions
Basic Baking Ingredients and Their Functions
Mariz Pascua
 
Experimental research design
Experimental research designExperimental research design
Experimental research designNursing Path
 
Cloud computing project report
Cloud computing project reportCloud computing project report
Cloud computing project report
Naveed Farooq
 

Viewers also liked (12)

Consumption Pattern and Expenditure
Consumption Pattern and ExpenditureConsumption Pattern and Expenditure
Consumption Pattern and Expenditure
 
Bakery products
Bakery productsBakery products
Bakery products
 
Работа с Akka Сluster, @afiskon, scalaby#14
Работа с Akka Сluster, @afiskon, scalaby#14Работа с Akka Сluster, @afiskon, scalaby#14
Работа с Akka Сluster, @afiskon, scalaby#14
 
Marketing Research Design
Marketing Research DesignMarketing Research Design
Marketing Research Design
 
Effect of Marketing Mix Elements
Effect of Marketing Mix ElementsEffect of Marketing Mix Elements
Effect of Marketing Mix Elements
 
Presentation Of Research Work
Presentation Of Research WorkPresentation Of Research Work
Presentation Of Research Work
 
Research Presentation Format
Research Presentation FormatResearch Presentation Format
Research Presentation Format
 
Research project ppt
Research project pptResearch project ppt
Research project ppt
 
Marketing mix the 7 p's of marketing
Marketing mix  the 7 p's of marketingMarketing mix  the 7 p's of marketing
Marketing mix the 7 p's of marketing
 
Basic Baking Ingredients and Their Functions
Basic Baking Ingredients and Their FunctionsBasic Baking Ingredients and Their Functions
Basic Baking Ingredients and Their Functions
 
Experimental research design
Experimental research designExperimental research design
Experimental research design
 
Cloud computing project report
Cloud computing project reportCloud computing project report
Cloud computing project report
 

More from Vasil Remeniuk

Product Minsk - РТБ и Программатик
Product Minsk - РТБ и ПрограмматикProduct Minsk - РТБ и Программатик
Product Minsk - РТБ и Программатик
Vasil Remeniuk
 
Scala laboratory: Globus. iteration #3
Scala laboratory: Globus. iteration #3Scala laboratory: Globus. iteration #3
Scala laboratory: Globus. iteration #3
Vasil Remeniuk
 
Testing in Scala by Adform research
Testing in Scala by Adform researchTesting in Scala by Adform research
Testing in Scala by Adform research
Vasil Remeniuk
 
Spark Intro by Adform Research
Spark Intro by Adform ResearchSpark Intro by Adform Research
Spark Intro by Adform ResearchVasil Remeniuk
 
Types by Adform Research, Saulius Valatka
Types by Adform Research, Saulius ValatkaTypes by Adform Research, Saulius Valatka
Types by Adform Research, Saulius ValatkaVasil Remeniuk
 
Types by Adform Research
Types by Adform ResearchTypes by Adform Research
Types by Adform ResearchVasil Remeniuk
 
Scalding by Adform Research, Alex Gryzlov
Scalding by Adform Research, Alex GryzlovScalding by Adform Research, Alex Gryzlov
Scalding by Adform Research, Alex GryzlovVasil Remeniuk
 
Scalding by Adform Research, Alex Gryzlov
Scalding by Adform Research, Alex GryzlovScalding by Adform Research, Alex Gryzlov
Scalding by Adform Research, Alex GryzlovVasil Remeniuk
 
Spark by Adform Research, Paulius
Spark by Adform Research, PauliusSpark by Adform Research, Paulius
Spark by Adform Research, PauliusVasil Remeniuk
 
Scala Style by Adform Research (Saulius Valatka)
Scala Style by Adform Research (Saulius Valatka)Scala Style by Adform Research (Saulius Valatka)
Scala Style by Adform Research (Saulius Valatka)Vasil Remeniuk
 
Spark intro by Adform Research
Spark intro by Adform ResearchSpark intro by Adform Research
Spark intro by Adform ResearchVasil Remeniuk
 
SBT by Aform Research, Saulius Valatka
SBT by Aform Research, Saulius ValatkaSBT by Aform Research, Saulius Valatka
SBT by Aform Research, Saulius ValatkaVasil Remeniuk
 
Scala laboratory: Globus. iteration #2
Scala laboratory: Globus. iteration #2Scala laboratory: Globus. iteration #2
Scala laboratory: Globus. iteration #2
Vasil Remeniuk
 
Testing in Scala. Adform Research
Testing in Scala. Adform ResearchTesting in Scala. Adform Research
Testing in Scala. Adform Research
Vasil Remeniuk
 
Scala laboratory. Globus. iteration #1
Scala laboratory. Globus. iteration #1Scala laboratory. Globus. iteration #1
Scala laboratory. Globus. iteration #1
Vasil Remeniuk
 
Cassandra + Spark + Elk
Cassandra + Spark + ElkCassandra + Spark + Elk
Cassandra + Spark + Elk
Vasil Remeniuk
 
Опыт использования Spark, Основано на реальных событиях
Опыт использования Spark, Основано на реальных событияхОпыт использования Spark, Основано на реальных событиях
Опыт использования Spark, Основано на реальных событиях
Vasil Remeniuk
 
ETL со Spark
ETL со SparkETL со Spark
ETL со Spark
Vasil Remeniuk
 
Funtional Reactive Programming with Examples in Scala + GWT
Funtional Reactive Programming with Examples in Scala + GWTFuntional Reactive Programming with Examples in Scala + GWT
Funtional Reactive Programming with Examples in Scala + GWT
Vasil Remeniuk
 
Vaadin+Scala
Vaadin+ScalaVaadin+Scala
Vaadin+Scala
Vasil Remeniuk
 

More from Vasil Remeniuk (20)

Product Minsk - РТБ и Программатик
Product Minsk - РТБ и ПрограмматикProduct Minsk - РТБ и Программатик
Product Minsk - РТБ и Программатик
 
Scala laboratory: Globus. iteration #3
Scala laboratory: Globus. iteration #3Scala laboratory: Globus. iteration #3
Scala laboratory: Globus. iteration #3
 
Testing in Scala by Adform research
Testing in Scala by Adform researchTesting in Scala by Adform research
Testing in Scala by Adform research
 
Spark Intro by Adform Research
Spark Intro by Adform ResearchSpark Intro by Adform Research
Spark Intro by Adform Research
 
Types by Adform Research, Saulius Valatka
Types by Adform Research, Saulius ValatkaTypes by Adform Research, Saulius Valatka
Types by Adform Research, Saulius Valatka
 
Types by Adform Research
Types by Adform ResearchTypes by Adform Research
Types by Adform Research
 
Scalding by Adform Research, Alex Gryzlov
Scalding by Adform Research, Alex GryzlovScalding by Adform Research, Alex Gryzlov
Scalding by Adform Research, Alex Gryzlov
 
Scalding by Adform Research, Alex Gryzlov
Scalding by Adform Research, Alex GryzlovScalding by Adform Research, Alex Gryzlov
Scalding by Adform Research, Alex Gryzlov
 
Spark by Adform Research, Paulius
Spark by Adform Research, PauliusSpark by Adform Research, Paulius
Spark by Adform Research, Paulius
 
Scala Style by Adform Research (Saulius Valatka)
Scala Style by Adform Research (Saulius Valatka)Scala Style by Adform Research (Saulius Valatka)
Scala Style by Adform Research (Saulius Valatka)
 
Spark intro by Adform Research
Spark intro by Adform ResearchSpark intro by Adform Research
Spark intro by Adform Research
 
SBT by Aform Research, Saulius Valatka
SBT by Aform Research, Saulius ValatkaSBT by Aform Research, Saulius Valatka
SBT by Aform Research, Saulius Valatka
 
Scala laboratory: Globus. iteration #2
Scala laboratory: Globus. iteration #2Scala laboratory: Globus. iteration #2
Scala laboratory: Globus. iteration #2
 
Testing in Scala. Adform Research
Testing in Scala. Adform ResearchTesting in Scala. Adform Research
Testing in Scala. Adform Research
 
Scala laboratory. Globus. iteration #1
Scala laboratory. Globus. iteration #1Scala laboratory. Globus. iteration #1
Scala laboratory. Globus. iteration #1
 
Cassandra + Spark + Elk
Cassandra + Spark + ElkCassandra + Spark + Elk
Cassandra + Spark + Elk
 
Опыт использования Spark, Основано на реальных событиях
Опыт использования Spark, Основано на реальных событияхОпыт использования Spark, Основано на реальных событиях
Опыт использования Spark, Основано на реальных событиях
 
ETL со Spark
ETL со SparkETL со Spark
ETL со Spark
 
Funtional Reactive Programming with Examples in Scala + GWT
Funtional Reactive Programming with Examples in Scala + GWTFuntional Reactive Programming with Examples in Scala + GWT
Funtional Reactive Programming with Examples in Scala + GWT
 
Vaadin+Scala
Vaadin+ScalaVaadin+Scala
Vaadin+Scala
 

Recently uploaded

Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
Alison B. Lowndes
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
ControlCase
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
DanBrown980551
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
DianaGray10
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
91mobiles
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
BookNet Canada
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
Kari Kakkonen
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Product School
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
Paul Groth
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
Dorra BARTAGUIZ
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Albert Hoitingh
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Product School
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
Product School
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Laura Byrne
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
Cheryl Hung
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
Sri Ambati
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
Prayukth K V
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Thierry Lestable
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
Guy Korland
 

Recently uploaded (20)

Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
 

Cake pattern. Presentation by Alex Famin at scalaby#14

  • 2. 2
  • 8. class ShoppingRobot(listProvider: ShopListProvider, location: GeoLocation) { def goShopping() = { val list = listProvider.get val shop = location.findNearestShop shop.map(buy(_, list)) } def buy(shop:Shop, list:List[Item]) = ??? } class ShopListProvider { def get:List[Item] = ??? } class GeoLocation { def findNearestShop:Maybe[Shop] = ??? } 8 Dependencies
  • 9. object Application extends App { val shoplistProvider = new ShopListProvider(); val location = new GeoLocation(); val robot = new ShoppingRobot(shopListProvider, location); robot.goShopping } 9 InjectionConstructor
  • 11. trait ShopListProviderComponent { val shopListProvider: ShopListProvider trait ShopListProvider { def get: List[Item] } } trait GeoLocationComponent { val geoLocation: GeoLocation trait GeoLocation { def findNearestShop: Maybe[Shop] } } 11 trait ShoppingRobotComponent { val robot: ShoppingRobot trait ShoppingRobot { def goShopping: Maybe[Purchase] } }
  • 12. trait ShopListProviderComponentImpl extends ShopListProviderComponent { val shopListProvider: ShopListProvider = new ShopListProviderImpl class ShopListProviderImpl extends ShopListProvider { override def get: List[Item] = ??? } } trait GeoLocationComponentImpl extends GeoLocationComponent { val geoLocation: GeoLocation = new GeoLocationImpl class GeoLocationImpl extends GeoLocation { override def findNearestShop: Maybe[Shop] = ??? } } 12
  • 13. trait ShoppingRobotComponentImpl extends ShoppingRobotComponent { this: ShoppingRobotComponentImpl with ShopListProviderComponent with GeoLocationComponent => val robot: ShoppingRobot = new DefaultRobot class DefaultRobot extends ShoppingRobot { override def goShopping: Maybe[Purchase] = { val list = listProvider.get val shop = location.findNearestShop shop.map(buy(_, list)) } } } 13 Dependency
  • 14. object Registry extends ShoppingRobotComponentImpl with GeoLocationComponentImpl with ShopListProviderComponentImpl object Application extends App { val robot = Registry.robot robot.goShopping } 14 Injection
  • 15. object FailedRegistry extends ShoppingRobotComponentImpl with GeoLocationComponentImpl error: illegal inheritance; self-type FailedRegistry.type does not conform to ShoppingRobotComponentImpl's selftype ShoppingRobotComponentImpl with ShopListProviderComponent with GeoLocationComponent object FailedRegistry extends ShoppingRobotComponentImpl with GeoLocationComponentImpl 15
  • 16. object TestRegistry extends ShoppingRobotComponentImpl with FakeGeoLocationComponentImpl with FakeShopListProviderComponentImpl class Registry2(shop: Shop) extends ShoppingRobotComponentImpl with ShopListProviderComponentImpl with GeoLocationComponent { val geoLocation: GeoLocation = new GeoLocation { override def findNearestShop: Maybe[Shop] = Some(shop) } } 16
  • 17. Pros and Cons + Pure Scala + Compile time validation 17 − Boilerplate overhead − Weak lifecycle control