SlideShare a Scribd company logo
1 of 17
Download to read offline
Закон Деметры
Лекция 3
GRASP
General Responsibility Assignment Software Patterns
● Polymorphism
● Low Coupling
● High Cohesion
● …
● Information Expert
● Creator
● Controller
● Pure Fabrication
● ...
Polymorphism
ILamp
DaylightLamp
constructor(supported_colors:[color])
+get_supported_colors(): [color]
+set_intensity(int)
+get_intensity(): int
+set_color(string)
+get_color(): string
ColoredLamp
white
white, blue,
green, red
~ supported_colors_: [color]
Polymorphism
ILamp
DaylightLamp
+get_supported_colors(): [color]
+set_intensity(int)
+get_intensity(): int
+set_color(string)
+get_color(): string
ILamp
DaylightLamp
constructor(supported_colors:[color])
+get_supported_colors(): [color]
+set_intensity(int)
+get_intensity(): int
+set_color(string)
+get_color(): string
ColoredLamp
white
white, blue,
green, red
+get_supported_colors():
return [white]
~ supported_colors_: [color]
DaylightLamp
+get_supported_colors():
return [white, red, blue, green]
Low coupling, high cohesion
High coupling, low cohesion Low coupling, high cohesion
Law of Demeter
My vassal's vassal is not my vassal
(Вассал моего вассала - не мой вассал)
Law of Demeter
My vassal's vassal is not my vassal
(Вассал моего вассала - не мой вассал)
IRoom
constructor(max_lamps: dict)
+calculate_payment(): float
+add_lamp(lamp_type=daylight)
+get_lamps(): dict
+is_lamp_allowed(lamp_type): bool
~ max_lamps_: dict(lamp_type, int)
~ lamps_: dict(lamp_type, ILamp)
IFloor
constructor(rooms: [IRoom])
+get_rooms(): [IRoom]
~ rooms_: [IRoom]
ILamp
constructor(supported_colors:[color])
+get_supported_colors(): [color]
+set_intensity(int)
+get_intensity(): int
+set_color(string)
+get_color(): string
~ supported_colors_: [color]
IFloorLampPolicy
+evaluate(is_day: bool)
+switch_all(color: color, intensity: int)
+get_floor(): IFloor
+set_floor(floor: IFloor)
~ floor_: IFloor
Law of Demeter
Law of Demeter
IFloorLampPolicy
+evaluate(is_day: bool)
+get_floor(): IFloor
+set_floor(floor: IFloor)
~ floor_: IFloor
class IFloorLampPolicy:
def evaluate(self, is_day: bool):
pass
class CurfewPolicy(IFloorLampPolicy):
def evaluate(self, is_day: bool):
if is_day:
return
# Turn all light off in the floor
for room in self.get_floor().get_rooms():
for _, lamps in room.get_lamps().items():
for lamp in lamps:
lamp.set_color(white)
lamp.set_intensity(0)
CurfewPolicy
Law of Demeter
IFloorLampPolicy
+evaluate(is_day: bool)
+get_floor(): IFloor
+set_floor(floor: IFloor)
~ floor_: IFloor
class IFloorLampPolicy:
def evaluate(self, is_day: bool):
pass
class CurfewPolicy(IFloorLampPolicy):
def evaluate(self, is_day: bool):
if is_day:
return
# Turn all light off in the floor
for room in self.get_floor().get_rooms():
for _, lamps in room.get_lamps().items():
for lamp in lamps:
lamp.set_color(white)
lamp.set_intensity(0)
CurfewPolicy
Law of Demeter violation (High Coupling):
get_floor() -> get_rooms() -> get_lamps()
Law of Demeter violation
IFloorLampPolicy
+get_floor(): IFloor
~ floor_: IFloor
IRoom
+get_lamps(): dict
~ lamps_: dict(lamp_type, ILamp)
IFloor
+get_rooms(): [IRoom]
~ rooms_: [IRoom]
ILamp
Law of Demeter violation problems
IFloor
constructor(rooms: [IRoom])
+get_rooms(): [IRoom]
~ rooms_: [IRoom]
IFloor
constructor(rooms: [IRoom], corridor: IRoom)
+get_rooms(): [IRoom]
+get_corridor(): IToom
~ rooms_: [IRoom]
~ corridor_: IRoom
class IFloorLampPolicy:
def evaluate(self, is_day: bool):
pass
class CurfewPolicy(IFloorLampPolicy):
def evaluate(self, is_day: bool):
if is_day:
return
# Turn all light off in the floor
for room in self.get_floor().get_rooms():
for _, lamps in room.get_lamps().items():
for lamp in lamps:
lamp.set_color(white)
lamp.set_intensity(0)
Law of Demeter violation problems
IFloor
constructor(rooms: [IRoom])
+get_rooms(): [IRoom]
~ rooms_: [IRoom]
IFloor
constructor(rooms: [IRoom], corridor: IRoom)
+get_rooms(): [IRoom]
+get_corridor(): IToom
~ rooms_: [IRoom]
~ corridor_: IRoom
class IFloorLampPolicy:
def evaluate(self, is_day: bool):
pass
class CurfewPolicy(IFloorLampPolicy):
def evaluate(self, is_day: bool):
if is_day:
return
# Turn all light off in the floor
for room in self.get_floor().get_rooms():
for _, lamps in room.get_lamps().items():
for lamp in lamps:
lamp.set_color(white)
lamp.set_intensity(0)
Avoiding Law of Demeter violation
IRoom
+get_lamps(): dict
+apply_action(action: LampAction)
~ lamps_: dict(lamp_type, ILamp)
IFloor
+get_rooms(): [IRoom]
+apply_action(action: LampAction)
~ rooms_: [IRoom]
ILamp
IFloorLampPolicy
+get_floor(): IFloor
~ floor_: IFloor
ILampAction
+evaluate(lamp: ILamp)
LampOff
Avoiding Law of Demeter violation
class IRoom:
def apply_action(self, action: ILampAction):
for lamp_type, lamps in self.lamps_.items():
for lamp in lamps:
action.evaluate(lamp)
class IFloor:
def apply_action(self, action: ILampAction):
for room in self.rooms_:
room.apply_action(action)
self.corridor_.apply_action(action)
class CurfewPolicy(IFloorLampPolicy):
def evaluate(self, is_day: bool):
if is_day:
return
floor = self.get_floor()
floor.apply_action(LampOff())
class ILampAction:
def evaluate(self, lamp: ILamp):
pass
class LampOff(ILampAction):
def evaluate(self, lamp: ILamp):
lamp.set_color(white)
lamp.set_intensity(0)
class LampOn(ILampAction):
def evaluate(self, lamp: ILamp):
lamp.set_intensity(100)
class RedLampOff(ILampAction):
def evaluate(self, lamp: ILamp):
if lamp.get_color() == red:
lamp.set_intensity(0)
Avoiding Law of Demeter violation
IRoom
+get_lamps(): dict
+apply_action(action: ILampAction)
~ lamps_: dict(lamp_type, ILamp)
IFloor
+get_rooms(): [IRoom]
+apply_action(action: IRoomAction)
~ rooms_: [IRoom]
ILampILampAction
+evaluate(lamp: ILamp)
IRoomAction
+evaluate(room: IRoom)
IFloorLampPolicy
+get_floor(): IFloor
~ floor_: IFloor
The end

More Related Content

What's hot

What Shazam doesn't want you to know
What Shazam doesn't want you to knowWhat Shazam doesn't want you to know
What Shazam doesn't want you to knowRoy van Rijn
 
Python: The Iterator Pattern (Comprehensions)
Python: The Iterator Pattern (Comprehensions)Python: The Iterator Pattern (Comprehensions)
Python: The Iterator Pattern (Comprehensions)Damian T. Gordon
 
Data made out of functions
Data made out of functionsData made out of functions
Data made out of functionskenbot
 
Functional Programming inside OOP? It’s possible with Python
Functional Programming inside OOP? It’s possible with PythonFunctional Programming inside OOP? It’s possible with Python
Functional Programming inside OOP? It’s possible with PythonCarlos V.
 
Introduction to NumPy for Machine Learning Programmers
Introduction to NumPy for Machine Learning ProgrammersIntroduction to NumPy for Machine Learning Programmers
Introduction to NumPy for Machine Learning ProgrammersKimikazu Kato
 
Beyond tf idf why, what & how
Beyond tf idf why, what & howBeyond tf idf why, what & how
Beyond tf idf why, what & howlucenerevolution
 
Python Training Tutorial for Frreshers
Python Training Tutorial for FrreshersPython Training Tutorial for Frreshers
Python Training Tutorial for Frreshersrajkamaltibacademy
 
String in python use of split method
String in python use of split methodString in python use of split method
String in python use of split methodvikram mahendra
 
Python language data types
Python language data typesPython language data types
Python language data typesHoang Nguyen
 
Introduction to Python and TensorFlow
Introduction to Python and TensorFlowIntroduction to Python and TensorFlow
Introduction to Python and TensorFlowBayu Aldi Yansyah
 
Introduction to the basics of Python programming (part 1)
Introduction to the basics of Python programming (part 1)Introduction to the basics of Python programming (part 1)
Introduction to the basics of Python programming (part 1)Pedro Rodrigues
 
Monoids, monoids, monoids
Monoids, monoids, monoidsMonoids, monoids, monoids
Monoids, monoids, monoidsLuka Jacobowitz
 
Pythonbrasil - 2018 - Acelerando Soluções com GPU
Pythonbrasil - 2018 - Acelerando Soluções com GPUPythonbrasil - 2018 - Acelerando Soluções com GPU
Pythonbrasil - 2018 - Acelerando Soluções com GPUPaulo Sergio Lemes Queiroz
 
Python Training v2
Python Training v2Python Training v2
Python Training v2ibaydan
 

What's hot (20)

What Shazam doesn't want you to know
What Shazam doesn't want you to knowWhat Shazam doesn't want you to know
What Shazam doesn't want you to know
 
Python: The Iterator Pattern (Comprehensions)
Python: The Iterator Pattern (Comprehensions)Python: The Iterator Pattern (Comprehensions)
Python: The Iterator Pattern (Comprehensions)
 
Data made out of functions
Data made out of functionsData made out of functions
Data made out of functions
 
Python Tidbits
Python TidbitsPython Tidbits
Python Tidbits
 
Code Generation
Code GenerationCode Generation
Code Generation
 
Functional Programming inside OOP? It’s possible with Python
Functional Programming inside OOP? It’s possible with PythonFunctional Programming inside OOP? It’s possible with Python
Functional Programming inside OOP? It’s possible with Python
 
Session1
Session1Session1
Session1
 
Introduction to NumPy for Machine Learning Programmers
Introduction to NumPy for Machine Learning ProgrammersIntroduction to NumPy for Machine Learning Programmers
Introduction to NumPy for Machine Learning Programmers
 
Beyond tf idf why, what & how
Beyond tf idf why, what & howBeyond tf idf why, what & how
Beyond tf idf why, what & how
 
Python Training Tutorial for Frreshers
Python Training Tutorial for FrreshersPython Training Tutorial for Frreshers
Python Training Tutorial for Frreshers
 
Erlang
ErlangErlang
Erlang
 
String in python use of split method
String in python use of split methodString in python use of split method
String in python use of split method
 
Py3k
Py3kPy3k
Py3k
 
NumPy/SciPy Statistics
NumPy/SciPy StatisticsNumPy/SciPy Statistics
NumPy/SciPy Statistics
 
Python language data types
Python language data typesPython language data types
Python language data types
 
Introduction to Python and TensorFlow
Introduction to Python and TensorFlowIntroduction to Python and TensorFlow
Introduction to Python and TensorFlow
 
Introduction to the basics of Python programming (part 1)
Introduction to the basics of Python programming (part 1)Introduction to the basics of Python programming (part 1)
Introduction to the basics of Python programming (part 1)
 
Monoids, monoids, monoids
Monoids, monoids, monoidsMonoids, monoids, monoids
Monoids, monoids, monoids
 
Pythonbrasil - 2018 - Acelerando Soluções com GPU
Pythonbrasil - 2018 - Acelerando Soluções com GPUPythonbrasil - 2018 - Acelerando Soluções com GPU
Pythonbrasil - 2018 - Acelerando Soluções com GPU
 
Python Training v2
Python Training v2Python Training v2
Python Training v2
 

Similar to Закон Деметры / Demetra's law

Object Orientation vs. Functional Programming in Python
Object Orientation vs. Functional Programming in PythonObject Orientation vs. Functional Programming in Python
Object Orientation vs. Functional Programming in PythonPython Ireland
 
Python于Web 2.0网站的应用 - QCon Beijing 2010
Python于Web 2.0网站的应用 - QCon Beijing 2010Python于Web 2.0网站的应用 - QCon Beijing 2010
Python于Web 2.0网站的应用 - QCon Beijing 2010Qiangning Hong
 
Thinking in Functions: Functional Programming in Python
Thinking in Functions: Functional Programming in PythonThinking in Functions: Functional Programming in Python
Thinking in Functions: Functional Programming in PythonAnoop Thomas Mathew
 
Zope component architechture
Zope component architechtureZope component architechture
Zope component architechtureAnatoly Bubenkov
 
The Ring programming language version 1.5 book - Part 5 of 31
The Ring programming language version 1.5 book - Part 5 of 31The Ring programming language version 1.5 book - Part 5 of 31
The Ring programming language version 1.5 book - Part 5 of 31Mahmoud Samir Fayed
 
R. herves. clean code (theme)2
R. herves. clean code (theme)2R. herves. clean code (theme)2
R. herves. clean code (theme)2saber tabatabaee
 
The Ring programming language version 1.3 book - Part 18 of 88
The Ring programming language version 1.3 book - Part 18 of 88The Ring programming language version 1.3 book - Part 18 of 88
The Ring programming language version 1.3 book - Part 18 of 88Mahmoud Samir Fayed
 
8799.pdfOr else the work is fine only. Lot to learn buddy.... Improve your ba...
8799.pdfOr else the work is fine only. Lot to learn buddy.... Improve your ba...8799.pdfOr else the work is fine only. Lot to learn buddy.... Improve your ba...
8799.pdfOr else the work is fine only. Lot to learn buddy.... Improve your ba...Yashpatel821746
 
Or else the work is fine only. Lot to learn buddy.... Improve your basics in ...
Or else the work is fine only. Lot to learn buddy.... Improve your basics in ...Or else the work is fine only. Lot to learn buddy.... Improve your basics in ...
Or else the work is fine only. Lot to learn buddy.... Improve your basics in ...Yashpatel821746
 
PYTHONOr else the work is fine only. Lot to learn buddy.... Improve your basi...
PYTHONOr else the work is fine only. Lot to learn buddy.... Improve your basi...PYTHONOr else the work is fine only. Lot to learn buddy.... Improve your basi...
PYTHONOr else the work is fine only. Lot to learn buddy.... Improve your basi...Yashpatel821746
 
4Developers 2018: An Arma 3 mod success story - Creating a new game mode for ...
4Developers 2018: An Arma 3 mod success story - Creating a new game mode for ...4Developers 2018: An Arma 3 mod success story - Creating a new game mode for ...
4Developers 2018: An Arma 3 mod success story - Creating a new game mode for ...PROIDEA
 
Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...
Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...
Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...DRVaibhavmeshram1
 
python beginner talk slide
python beginner talk slidepython beginner talk slide
python beginner talk slidejonycse
 
The Ring programming language version 1.5.1 book - Part 174 of 180
The Ring programming language version 1.5.1 book - Part 174 of 180 The Ring programming language version 1.5.1 book - Part 174 of 180
The Ring programming language version 1.5.1 book - Part 174 of 180 Mahmoud Samir Fayed
 
The Ring programming language version 1.9 book - Part 98 of 210
The Ring programming language version 1.9 book - Part 98 of 210The Ring programming language version 1.9 book - Part 98 of 210
The Ring programming language version 1.9 book - Part 98 of 210Mahmoud Samir Fayed
 
Getting Started - Console Program and Problem Solving
Getting Started - Console Program and Problem SolvingGetting Started - Console Program and Problem Solving
Getting Started - Console Program and Problem SolvingHock Leng PUAH
 

Similar to Закон Деметры / Demetra's law (20)

Object Orientation vs. Functional Programming in Python
Object Orientation vs. Functional Programming in PythonObject Orientation vs. Functional Programming in Python
Object Orientation vs. Functional Programming in Python
 
Python于Web 2.0网站的应用 - QCon Beijing 2010
Python于Web 2.0网站的应用 - QCon Beijing 2010Python于Web 2.0网站的应用 - QCon Beijing 2010
Python于Web 2.0网站的应用 - QCon Beijing 2010
 
Functional python
Functional pythonFunctional python
Functional python
 
Python Part 1
Python Part 1Python Part 1
Python Part 1
 
Thinking in Functions: Functional Programming in Python
Thinking in Functions: Functional Programming in PythonThinking in Functions: Functional Programming in Python
Thinking in Functions: Functional Programming in Python
 
Zope component architechture
Zope component architechtureZope component architechture
Zope component architechture
 
The Ring programming language version 1.5 book - Part 5 of 31
The Ring programming language version 1.5 book - Part 5 of 31The Ring programming language version 1.5 book - Part 5 of 31
The Ring programming language version 1.5 book - Part 5 of 31
 
R. herves. clean code (theme)2
R. herves. clean code (theme)2R. herves. clean code (theme)2
R. herves. clean code (theme)2
 
The Ring programming language version 1.3 book - Part 18 of 88
The Ring programming language version 1.3 book - Part 18 of 88The Ring programming language version 1.3 book - Part 18 of 88
The Ring programming language version 1.3 book - Part 18 of 88
 
C3 w2
C3 w2C3 w2
C3 w2
 
8799.pdfOr else the work is fine only. Lot to learn buddy.... Improve your ba...
8799.pdfOr else the work is fine only. Lot to learn buddy.... Improve your ba...8799.pdfOr else the work is fine only. Lot to learn buddy.... Improve your ba...
8799.pdfOr else the work is fine only. Lot to learn buddy.... Improve your ba...
 
Or else the work is fine only. Lot to learn buddy.... Improve your basics in ...
Or else the work is fine only. Lot to learn buddy.... Improve your basics in ...Or else the work is fine only. Lot to learn buddy.... Improve your basics in ...
Or else the work is fine only. Lot to learn buddy.... Improve your basics in ...
 
PYTHONOr else the work is fine only. Lot to learn buddy.... Improve your basi...
PYTHONOr else the work is fine only. Lot to learn buddy.... Improve your basi...PYTHONOr else the work is fine only. Lot to learn buddy.... Improve your basi...
PYTHONOr else the work is fine only. Lot to learn buddy.... Improve your basi...
 
4Developers 2018: An Arma 3 mod success story - Creating a new game mode for ...
4Developers 2018: An Arma 3 mod success story - Creating a new game mode for ...4Developers 2018: An Arma 3 mod success story - Creating a new game mode for ...
4Developers 2018: An Arma 3 mod success story - Creating a new game mode for ...
 
Porting to Python 3
Porting to Python 3Porting to Python 3
Porting to Python 3
 
Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...
Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...
Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...
 
python beginner talk slide
python beginner talk slidepython beginner talk slide
python beginner talk slide
 
The Ring programming language version 1.5.1 book - Part 174 of 180
The Ring programming language version 1.5.1 book - Part 174 of 180 The Ring programming language version 1.5.1 book - Part 174 of 180
The Ring programming language version 1.5.1 book - Part 174 of 180
 
The Ring programming language version 1.9 book - Part 98 of 210
The Ring programming language version 1.9 book - Part 98 of 210The Ring programming language version 1.9 book - Part 98 of 210
The Ring programming language version 1.9 book - Part 98 of 210
 
Getting Started - Console Program and Problem Solving
Getting Started - Console Program and Problem SolvingGetting Started - Console Program and Problem Solving
Getting Started - Console Program and Problem Solving
 

More from Alexander Granin

Concurrent applications with free monads and stm
Concurrent applications with free monads and stmConcurrent applications with free monads and stm
Concurrent applications with free monads and stmAlexander Granin
 
Hierarchical free monads and software design in fp
Hierarchical free monads and software design in fpHierarchical free monads and software design in fp
Hierarchical free monads and software design in fpAlexander Granin
 
Final tagless vs free monad
Final tagless vs free monadFinal tagless vs free monad
Final tagless vs free monadAlexander Granin
 
The present and the future of functional programming in c++
The present and the future of functional programming in c++The present and the future of functional programming in c++
The present and the future of functional programming in c++Alexander Granin
 
О разработке десктопных приложений / About desktop development
О разработке десктопных приложений / About desktop developmentО разработке десктопных приложений / About desktop development
О разработке десктопных приложений / About desktop developmentAlexander Granin
 
Принципы и практики разработки ПО 2 / Principles and practices of software de...
Принципы и практики разработки ПО 2 / Principles and practices of software de...Принципы и практики разработки ПО 2 / Principles and practices of software de...
Принципы и практики разработки ПО 2 / Principles and practices of software de...Alexander Granin
 
Принципы и практики разработки ПО / Principles and practices of software deve...
Принципы и практики разработки ПО / Principles and practices of software deve...Принципы и практики разработки ПО / Principles and practices of software deve...
Принципы и практики разработки ПО / Principles and practices of software deve...Alexander Granin
 
Design of big applications in FP
Design of big applications in FPDesign of big applications in FP
Design of big applications in FPAlexander Granin
 
GitHub - зеркало разработчика
GitHub - зеркало разработчикаGitHub - зеркало разработчика
GitHub - зеркало разработчикаAlexander Granin
 
The Present and The Future of Functional Programming in C++
The Present and The Future of Functional Programming in C++The Present and The Future of Functional Programming in C++
The Present and The Future of Functional Programming in C++Alexander Granin
 
Functional programming in C++ LambdaNsk
Functional programming in C++ LambdaNskFunctional programming in C++ LambdaNsk
Functional programming in C++ LambdaNskAlexander Granin
 
Transition graph using free monads and existentials
Transition graph using free monads and existentialsTransition graph using free monads and existentials
Transition graph using free monads and existentialsAlexander Granin
 
Software transactional memory. pure functional approach
Software transactional memory. pure functional approachSoftware transactional memory. pure functional approach
Software transactional memory. pure functional approachAlexander Granin
 
Вы не понимаете ФП / You don't understand FP
Вы не понимаете ФП / You don't understand FPВы не понимаете ФП / You don't understand FP
Вы не понимаете ФП / You don't understand FPAlexander Granin
 
Functional "Life": parallel cellular automata and comonads
Functional "Life": parallel cellular automata and comonadsFunctional "Life": parallel cellular automata and comonads
Functional "Life": parallel cellular automata and comonadsAlexander Granin
 
Functional microscope - Lenses in C++
Functional microscope - Lenses in C++Functional microscope - Lenses in C++
Functional microscope - Lenses in C++Alexander Granin
 
Дизайн больших приложений в ФП
Дизайн больших приложений в ФПДизайн больших приложений в ФП
Дизайн больших приложений в ФПAlexander Granin
 
Линзы - комбинаторная манипуляция данными
Линзы - комбинаторная манипуляция даннымиЛинзы - комбинаторная манипуляция данными
Линзы - комбинаторная манипуляция даннымиAlexander Granin
 
Линзы - комбинаторная манипуляция данными (Dev2Dev)
Линзы - комбинаторная манипуляция данными (Dev2Dev)Линзы - комбинаторная манипуляция данными (Dev2Dev)
Линзы - комбинаторная манипуляция данными (Dev2Dev)Alexander Granin
 

More from Alexander Granin (20)

Concurrent applications with free monads and stm
Concurrent applications with free monads and stmConcurrent applications with free monads and stm
Concurrent applications with free monads and stm
 
Hierarchical free monads and software design in fp
Hierarchical free monads and software design in fpHierarchical free monads and software design in fp
Hierarchical free monads and software design in fp
 
Final tagless vs free monad
Final tagless vs free monadFinal tagless vs free monad
Final tagless vs free monad
 
Monadic parsers in C++
Monadic parsers in C++Monadic parsers in C++
Monadic parsers in C++
 
The present and the future of functional programming in c++
The present and the future of functional programming in c++The present and the future of functional programming in c++
The present and the future of functional programming in c++
 
О разработке десктопных приложений / About desktop development
О разработке десктопных приложений / About desktop developmentО разработке десктопных приложений / About desktop development
О разработке десктопных приложений / About desktop development
 
Принципы и практики разработки ПО 2 / Principles and practices of software de...
Принципы и практики разработки ПО 2 / Principles and practices of software de...Принципы и практики разработки ПО 2 / Principles and practices of software de...
Принципы и практики разработки ПО 2 / Principles and practices of software de...
 
Принципы и практики разработки ПО / Principles and practices of software deve...
Принципы и практики разработки ПО / Principles and practices of software deve...Принципы и практики разработки ПО / Principles and practices of software deve...
Принципы и практики разработки ПО / Principles and practices of software deve...
 
Design of big applications in FP
Design of big applications in FPDesign of big applications in FP
Design of big applications in FP
 
GitHub - зеркало разработчика
GitHub - зеркало разработчикаGitHub - зеркало разработчика
GitHub - зеркало разработчика
 
The Present and The Future of Functional Programming in C++
The Present and The Future of Functional Programming in C++The Present and The Future of Functional Programming in C++
The Present and The Future of Functional Programming in C++
 
Functional programming in C++ LambdaNsk
Functional programming in C++ LambdaNskFunctional programming in C++ LambdaNsk
Functional programming in C++ LambdaNsk
 
Transition graph using free monads and existentials
Transition graph using free monads and existentialsTransition graph using free monads and existentials
Transition graph using free monads and existentials
 
Software transactional memory. pure functional approach
Software transactional memory. pure functional approachSoftware transactional memory. pure functional approach
Software transactional memory. pure functional approach
 
Вы не понимаете ФП / You don't understand FP
Вы не понимаете ФП / You don't understand FPВы не понимаете ФП / You don't understand FP
Вы не понимаете ФП / You don't understand FP
 
Functional "Life": parallel cellular automata and comonads
Functional "Life": parallel cellular automata and comonadsFunctional "Life": parallel cellular automata and comonads
Functional "Life": parallel cellular automata and comonads
 
Functional microscope - Lenses in C++
Functional microscope - Lenses in C++Functional microscope - Lenses in C++
Functional microscope - Lenses in C++
 
Дизайн больших приложений в ФП
Дизайн больших приложений в ФПДизайн больших приложений в ФП
Дизайн больших приложений в ФП
 
Линзы - комбинаторная манипуляция данными
Линзы - комбинаторная манипуляция даннымиЛинзы - комбинаторная манипуляция данными
Линзы - комбинаторная манипуляция данными
 
Линзы - комбинаторная манипуляция данными (Dev2Dev)
Линзы - комбинаторная манипуляция данными (Dev2Dev)Линзы - комбинаторная манипуляция данными (Dev2Dev)
Линзы - комбинаторная манипуляция данными (Dev2Dev)
 

Recently uploaded

Introduction to FIDO Authentication and Passkeys.pptx
Introduction to FIDO Authentication and Passkeys.pptxIntroduction to FIDO Authentication and Passkeys.pptx
Introduction to FIDO Authentication and Passkeys.pptxFIDO Alliance
 
Using IESVE for Room Loads Analysis - UK & Ireland
Using IESVE for Room Loads Analysis - UK & IrelandUsing IESVE for Room Loads Analysis - UK & Ireland
Using IESVE for Room Loads Analysis - UK & IrelandIES VE
 
“Iamnobody89757” Understanding the Mysterious of Digital Identity.pdf
“Iamnobody89757” Understanding the Mysterious of Digital Identity.pdf“Iamnobody89757” Understanding the Mysterious of Digital Identity.pdf
“Iamnobody89757” Understanding the Mysterious of Digital Identity.pdfMuhammad Subhan
 
ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...
ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...
ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...FIDO Alliance
 
TopCryptoSupers 12thReport OrionX May2024
TopCryptoSupers 12thReport OrionX May2024TopCryptoSupers 12thReport OrionX May2024
TopCryptoSupers 12thReport OrionX May2024Stephen Perrenod
 
Generative AI Use Cases and Applications.pdf
Generative AI Use Cases and Applications.pdfGenerative AI Use Cases and Applications.pdf
Generative AI Use Cases and Applications.pdfalexjohnson7307
 
Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...
Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...
Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...ScyllaDB
 
Top 10 CodeIgniter Development Companies
Top 10 CodeIgniter Development CompaniesTop 10 CodeIgniter Development Companies
Top 10 CodeIgniter Development CompaniesTopCSSGallery
 
Working together SRE & Platform Engineering
Working together SRE & Platform EngineeringWorking together SRE & Platform Engineering
Working together SRE & Platform EngineeringMarcus Vechiato
 
WebRTC and SIP not just audio and video @ OpenSIPS 2024
WebRTC and SIP not just audio and video @ OpenSIPS 2024WebRTC and SIP not just audio and video @ OpenSIPS 2024
WebRTC and SIP not just audio and video @ OpenSIPS 2024Lorenzo Miniero
 
Portal Kombat : extension du réseau de propagande russe
Portal Kombat : extension du réseau de propagande russePortal Kombat : extension du réseau de propagande russe
Portal Kombat : extension du réseau de propagande russe中 央社
 
Extensible Python: Robustness through Addition - PyCon 2024
Extensible Python: Robustness through Addition - PyCon 2024Extensible Python: Robustness through Addition - PyCon 2024
Extensible Python: Robustness through Addition - PyCon 2024Patrick Viafore
 
State of the Smart Building Startup Landscape 2024!
State of the Smart Building Startup Landscape 2024!State of the Smart Building Startup Landscape 2024!
State of the Smart Building Startup Landscape 2024!Memoori
 
Google I/O Extended 2024 Warsaw
Google I/O Extended 2024 WarsawGoogle I/O Extended 2024 Warsaw
Google I/O Extended 2024 WarsawGDSC PJATK
 
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...TrustArc
 
Observability Concepts EVERY Developer Should Know (DevOpsDays Seattle)
Observability Concepts EVERY Developer Should Know (DevOpsDays Seattle)Observability Concepts EVERY Developer Should Know (DevOpsDays Seattle)
Observability Concepts EVERY Developer Should Know (DevOpsDays Seattle)Paige Cruz
 
Hyatt driving innovation and exceptional customer experiences with FIDO passw...
Hyatt driving innovation and exceptional customer experiences with FIDO passw...Hyatt driving innovation and exceptional customer experiences with FIDO passw...
Hyatt driving innovation and exceptional customer experiences with FIDO passw...FIDO Alliance
 
Human Expert Website Manual WCAG 2.0 2.1 2.2 Audit - Digital Accessibility Au...
Human Expert Website Manual WCAG 2.0 2.1 2.2 Audit - Digital Accessibility Au...Human Expert Website Manual WCAG 2.0 2.1 2.2 Audit - Digital Accessibility Au...
Human Expert Website Manual WCAG 2.0 2.1 2.2 Audit - Digital Accessibility Au...Skynet Technologies
 
Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...
Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...
Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...ScyllaDB
 

Recently uploaded (20)

Introduction to FIDO Authentication and Passkeys.pptx
Introduction to FIDO Authentication and Passkeys.pptxIntroduction to FIDO Authentication and Passkeys.pptx
Introduction to FIDO Authentication and Passkeys.pptx
 
Using IESVE for Room Loads Analysis - UK & Ireland
Using IESVE for Room Loads Analysis - UK & IrelandUsing IESVE for Room Loads Analysis - UK & Ireland
Using IESVE for Room Loads Analysis - UK & Ireland
 
“Iamnobody89757” Understanding the Mysterious of Digital Identity.pdf
“Iamnobody89757” Understanding the Mysterious of Digital Identity.pdf“Iamnobody89757” Understanding the Mysterious of Digital Identity.pdf
“Iamnobody89757” Understanding the Mysterious of Digital Identity.pdf
 
ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...
ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...
ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...
 
TopCryptoSupers 12thReport OrionX May2024
TopCryptoSupers 12thReport OrionX May2024TopCryptoSupers 12thReport OrionX May2024
TopCryptoSupers 12thReport OrionX May2024
 
Generative AI Use Cases and Applications.pdf
Generative AI Use Cases and Applications.pdfGenerative AI Use Cases and Applications.pdf
Generative AI Use Cases and Applications.pdf
 
Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...
Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...
Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...
 
Top 10 CodeIgniter Development Companies
Top 10 CodeIgniter Development CompaniesTop 10 CodeIgniter Development Companies
Top 10 CodeIgniter Development Companies
 
Overview of Hyperledger Foundation
Overview of Hyperledger FoundationOverview of Hyperledger Foundation
Overview of Hyperledger Foundation
 
Working together SRE & Platform Engineering
Working together SRE & Platform EngineeringWorking together SRE & Platform Engineering
Working together SRE & Platform Engineering
 
WebRTC and SIP not just audio and video @ OpenSIPS 2024
WebRTC and SIP not just audio and video @ OpenSIPS 2024WebRTC and SIP not just audio and video @ OpenSIPS 2024
WebRTC and SIP not just audio and video @ OpenSIPS 2024
 
Portal Kombat : extension du réseau de propagande russe
Portal Kombat : extension du réseau de propagande russePortal Kombat : extension du réseau de propagande russe
Portal Kombat : extension du réseau de propagande russe
 
Extensible Python: Robustness through Addition - PyCon 2024
Extensible Python: Robustness through Addition - PyCon 2024Extensible Python: Robustness through Addition - PyCon 2024
Extensible Python: Robustness through Addition - PyCon 2024
 
State of the Smart Building Startup Landscape 2024!
State of the Smart Building Startup Landscape 2024!State of the Smart Building Startup Landscape 2024!
State of the Smart Building Startup Landscape 2024!
 
Google I/O Extended 2024 Warsaw
Google I/O Extended 2024 WarsawGoogle I/O Extended 2024 Warsaw
Google I/O Extended 2024 Warsaw
 
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
 
Observability Concepts EVERY Developer Should Know (DevOpsDays Seattle)
Observability Concepts EVERY Developer Should Know (DevOpsDays Seattle)Observability Concepts EVERY Developer Should Know (DevOpsDays Seattle)
Observability Concepts EVERY Developer Should Know (DevOpsDays Seattle)
 
Hyatt driving innovation and exceptional customer experiences with FIDO passw...
Hyatt driving innovation and exceptional customer experiences with FIDO passw...Hyatt driving innovation and exceptional customer experiences with FIDO passw...
Hyatt driving innovation and exceptional customer experiences with FIDO passw...
 
Human Expert Website Manual WCAG 2.0 2.1 2.2 Audit - Digital Accessibility Au...
Human Expert Website Manual WCAG 2.0 2.1 2.2 Audit - Digital Accessibility Au...Human Expert Website Manual WCAG 2.0 2.1 2.2 Audit - Digital Accessibility Au...
Human Expert Website Manual WCAG 2.0 2.1 2.2 Audit - Digital Accessibility Au...
 
Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...
Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...
Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...
 

Закон Деметры / Demetra's law

  • 2. GRASP General Responsibility Assignment Software Patterns ● Polymorphism ● Low Coupling ● High Cohesion ● … ● Information Expert ● Creator ● Controller ● Pure Fabrication ● ...
  • 4. Polymorphism ILamp DaylightLamp +get_supported_colors(): [color] +set_intensity(int) +get_intensity(): int +set_color(string) +get_color(): string ILamp DaylightLamp constructor(supported_colors:[color]) +get_supported_colors(): [color] +set_intensity(int) +get_intensity(): int +set_color(string) +get_color(): string ColoredLamp white white, blue, green, red +get_supported_colors(): return [white] ~ supported_colors_: [color] DaylightLamp +get_supported_colors(): return [white, red, blue, green]
  • 5. Low coupling, high cohesion High coupling, low cohesion Low coupling, high cohesion
  • 6. Law of Demeter My vassal's vassal is not my vassal (Вассал моего вассала - не мой вассал)
  • 7. Law of Demeter My vassal's vassal is not my vassal (Вассал моего вассала - не мой вассал)
  • 8. IRoom constructor(max_lamps: dict) +calculate_payment(): float +add_lamp(lamp_type=daylight) +get_lamps(): dict +is_lamp_allowed(lamp_type): bool ~ max_lamps_: dict(lamp_type, int) ~ lamps_: dict(lamp_type, ILamp) IFloor constructor(rooms: [IRoom]) +get_rooms(): [IRoom] ~ rooms_: [IRoom] ILamp constructor(supported_colors:[color]) +get_supported_colors(): [color] +set_intensity(int) +get_intensity(): int +set_color(string) +get_color(): string ~ supported_colors_: [color] IFloorLampPolicy +evaluate(is_day: bool) +switch_all(color: color, intensity: int) +get_floor(): IFloor +set_floor(floor: IFloor) ~ floor_: IFloor Law of Demeter
  • 9. Law of Demeter IFloorLampPolicy +evaluate(is_day: bool) +get_floor(): IFloor +set_floor(floor: IFloor) ~ floor_: IFloor class IFloorLampPolicy: def evaluate(self, is_day: bool): pass class CurfewPolicy(IFloorLampPolicy): def evaluate(self, is_day: bool): if is_day: return # Turn all light off in the floor for room in self.get_floor().get_rooms(): for _, lamps in room.get_lamps().items(): for lamp in lamps: lamp.set_color(white) lamp.set_intensity(0) CurfewPolicy
  • 10. Law of Demeter IFloorLampPolicy +evaluate(is_day: bool) +get_floor(): IFloor +set_floor(floor: IFloor) ~ floor_: IFloor class IFloorLampPolicy: def evaluate(self, is_day: bool): pass class CurfewPolicy(IFloorLampPolicy): def evaluate(self, is_day: bool): if is_day: return # Turn all light off in the floor for room in self.get_floor().get_rooms(): for _, lamps in room.get_lamps().items(): for lamp in lamps: lamp.set_color(white) lamp.set_intensity(0) CurfewPolicy Law of Demeter violation (High Coupling): get_floor() -> get_rooms() -> get_lamps()
  • 11. Law of Demeter violation IFloorLampPolicy +get_floor(): IFloor ~ floor_: IFloor IRoom +get_lamps(): dict ~ lamps_: dict(lamp_type, ILamp) IFloor +get_rooms(): [IRoom] ~ rooms_: [IRoom] ILamp
  • 12. Law of Demeter violation problems IFloor constructor(rooms: [IRoom]) +get_rooms(): [IRoom] ~ rooms_: [IRoom] IFloor constructor(rooms: [IRoom], corridor: IRoom) +get_rooms(): [IRoom] +get_corridor(): IToom ~ rooms_: [IRoom] ~ corridor_: IRoom class IFloorLampPolicy: def evaluate(self, is_day: bool): pass class CurfewPolicy(IFloorLampPolicy): def evaluate(self, is_day: bool): if is_day: return # Turn all light off in the floor for room in self.get_floor().get_rooms(): for _, lamps in room.get_lamps().items(): for lamp in lamps: lamp.set_color(white) lamp.set_intensity(0)
  • 13. Law of Demeter violation problems IFloor constructor(rooms: [IRoom]) +get_rooms(): [IRoom] ~ rooms_: [IRoom] IFloor constructor(rooms: [IRoom], corridor: IRoom) +get_rooms(): [IRoom] +get_corridor(): IToom ~ rooms_: [IRoom] ~ corridor_: IRoom class IFloorLampPolicy: def evaluate(self, is_day: bool): pass class CurfewPolicy(IFloorLampPolicy): def evaluate(self, is_day: bool): if is_day: return # Turn all light off in the floor for room in self.get_floor().get_rooms(): for _, lamps in room.get_lamps().items(): for lamp in lamps: lamp.set_color(white) lamp.set_intensity(0)
  • 14. Avoiding Law of Demeter violation IRoom +get_lamps(): dict +apply_action(action: LampAction) ~ lamps_: dict(lamp_type, ILamp) IFloor +get_rooms(): [IRoom] +apply_action(action: LampAction) ~ rooms_: [IRoom] ILamp IFloorLampPolicy +get_floor(): IFloor ~ floor_: IFloor ILampAction +evaluate(lamp: ILamp) LampOff
  • 15. Avoiding Law of Demeter violation class IRoom: def apply_action(self, action: ILampAction): for lamp_type, lamps in self.lamps_.items(): for lamp in lamps: action.evaluate(lamp) class IFloor: def apply_action(self, action: ILampAction): for room in self.rooms_: room.apply_action(action) self.corridor_.apply_action(action) class CurfewPolicy(IFloorLampPolicy): def evaluate(self, is_day: bool): if is_day: return floor = self.get_floor() floor.apply_action(LampOff()) class ILampAction: def evaluate(self, lamp: ILamp): pass class LampOff(ILampAction): def evaluate(self, lamp: ILamp): lamp.set_color(white) lamp.set_intensity(0) class LampOn(ILampAction): def evaluate(self, lamp: ILamp): lamp.set_intensity(100) class RedLampOff(ILampAction): def evaluate(self, lamp: ILamp): if lamp.get_color() == red: lamp.set_intensity(0)
  • 16. Avoiding Law of Demeter violation IRoom +get_lamps(): dict +apply_action(action: ILampAction) ~ lamps_: dict(lamp_type, ILamp) IFloor +get_rooms(): [IRoom] +apply_action(action: IRoomAction) ~ rooms_: [IRoom] ILampILampAction +evaluate(lamp: ILamp) IRoomAction +evaluate(room: IRoom) IFloorLampPolicy +get_floor(): IFloor ~ floor_: IFloor