Jak zabrać się za wdrożenie Django na serwery oparte o systemy operacyjne Linuks. Co warto brać pod uwagę gdy aplikacja w Pythonie staje się popularna i potrzebuje więcej zasobów? PyGda 2016. Jak podejść do skalowania i wirtualizacji zasobów w 2016 roku
Prezentacja powstała na potrzeby webinara pt. Praca testera w Scrumie.
Podczas webinara Ola Woszczyk- testerka z testuj.pl, opowiedziała, o tym czym jest SCRUM i jak wygląda praca w zespole Scrumowym. Ponadto wyjaśniła, jaką rolę w Scrumie pełni tester i jakie najczęstsze błędy popełniają członkowie zespołu.
Prezentacja dostępna jest jako kolejny slajd po wyświetlonym filmie.
In presentation the idea of automatically generated web interface for remote laboratory is presented. The concept is based on suitably prepared set of metadata, that is used to generate web client. In presented solution each remote experiment, sends metadata concerning user interface just before experiment session is started.
Main advantages of this solution include: easier deployment and decreased development costs. This concept can be applied for various e-learning areas. The working example of such interface is shown and discussed.
Jak zabrać się za wdrożenie Django na serwery oparte o systemy operacyjne Linuks. Co warto brać pod uwagę gdy aplikacja w Pythonie staje się popularna i potrzebuje więcej zasobów? PyGda 2016. Jak podejść do skalowania i wirtualizacji zasobów w 2016 roku
Prezentacja powstała na potrzeby webinara pt. Praca testera w Scrumie.
Podczas webinara Ola Woszczyk- testerka z testuj.pl, opowiedziała, o tym czym jest SCRUM i jak wygląda praca w zespole Scrumowym. Ponadto wyjaśniła, jaką rolę w Scrumie pełni tester i jakie najczęstsze błędy popełniają członkowie zespołu.
Prezentacja dostępna jest jako kolejny slajd po wyświetlonym filmie.
Similar to Programowanie Komponentowe: #3 Podstawy programowania komponentów (11)
In presentation the idea of automatically generated web interface for remote laboratory is presented. The concept is based on suitably prepared set of metadata, that is used to generate web client. In presented solution each remote experiment, sends metadata concerning user interface just before experiment session is started.
Main advantages of this solution include: easier deployment and decreased development costs. This concept can be applied for various e-learning areas. The working example of such interface is shown and discussed.
This document describes sequential and parallel quicksort algorithms. Sequential quicksort has average complexity of O(n log n) but worst case of O(n^2). Parallel quicksort partitions the array, sorts subarrays in parallel threads, and waits for threads to complete to improve performance over sequential quicksort. It uses a queue to store threads if processors are busy and chooses split keys through various methods like first element or median. New threads are only created if the subarray size is above a minimum to reduce overhead.
5. Tworzenie oprogramowania
Tworzenie komponentów
Stabilna abstrakcja dziedzinowa
zmiana interfejsu ! zmiana wersji lub nowy interfejs
Ukryta reprezentacja danych
bezstanowe na zewnatrz
brak polegania na implementacji
Maksymalna niezaleznosc
mozliwosc rozszerzania
Funkcjonalny interfejs
Programowanie defensywne
kontrakty
niezmienniki
Zarzadzanie i wdrazanie
Mikołaj Olszewski (WZIM SGGW) Programowanie Komponentowe Wykład #3 5 / 71
27. Dobre praktyki Odpowiedzialnosci
Odpowiedzialnosci
zlepek danych
Mikołaj Olszewski (WZIM SGGW) Programowanie Komponentowe Wykład #3 21 / 71
28. Dobre praktyki Odpowiedzialnosci
Odpowiedzialnosci
zlepek danych
jednostka z odpowiedzialnosciami (zachowanie)
Mikołaj Olszewski (WZIM SGGW) Programowanie Komponentowe Wykład #3 21 / 71
29. Dobre praktyki Odpowiedzialnosci
Odpowiedzialnosci
zlepek danych
jednostka z odpowiedzialnosciami (zachowanie)
samoodpowiedzialnosc
Mikołaj Olszewski (WZIM SGGW) Programowanie Komponentowe Wykład #3 21 / 71
30. Dobre praktyki Odpowiedzialnosci
Przykład: winda
1 p u b l i c c l a s s E l e v a t o r
2 f
3 Door door ;
4 IEnumerable<Button> b u t t o n s ;
5 g
Mikołaj Olszewski (WZIM SGGW) Programowanie Komponentowe Wykład #3 22 / 71
31. Dobre praktyki Odpowiedzialnosci
Przykład: winda
1 p u b l i c i n t e r f a c e I E l e v a t o r
2 f
3 void C a l l ( ) ;
4 void GoToFloor ( i n t number ) ;
5 g
Mikołaj Olszewski (WZIM SGGW) Programowanie Komponentowe Wykład #3 22 / 71
33. Rozwiazania praktyczne Szczególne
Interfejsy
1 p u b l i c i n t e r f a c e I C a l c u l a t o r : IComponent
2 f
3 void c l e a r ( ) ;
4 double p r o c e s s ( double n1 , double n2 , IOp e r a t i o n op ) ;
5 IEnumerable<IOp e r a t i o n> a l l owe dOp e r a t i o n s ( ) ;
6 . . .
7 g
Mikołaj Olszewski (WZIM SGGW) Programowanie Komponentowe Wykład #3 24 / 71
34. Rozwiazania praktyczne Szczególne
Obiekty
1 p u b l i c c l a s s C a l c u l a t o r : I C a l c u l a t o r
2 f
3 p r i v a t e Ca l c u l a t o rFr ame frame ;
4 p r i v a t e TMode mode ;
5
6 [ Cat egor y ( ”Misc ” ) ]
7 p u b l i c TMode Mode
8 f
9 ge t f r e t u r n mode ; g
10 s e t
11 f
12 mode = v a l u e ;
13 frame . showHideButtons (mode ) ;
14 g
15 g
16 . . .
17 g
Mikołaj Olszewski (WZIM SGGW) Programowanie Komponentowe Wykład #3 25 / 71
35. Rozwiazania praktyczne Szczególne
Delegaty
1 p u b l i c c l a s s De l e g u j a c a
2 f
3 p r i v a t e De l e g a t d e l e g a t ;
4
5 p u b l i c o b j e c t De l e g a c j a ( o b j e c t param)
6 f
7 i f ( d e l e g a t != n u l l )
8 r e t u r n d e l e g a t . P r z y j e c i eDe l e g a c j i ( param) ;
9
10 r e t u r n n u l l ;
11 g
12 g
Mikołaj Olszewski (WZIM SGGW) Programowanie Komponentowe Wykład #3 26 / 71
36. Rozwiazania praktyczne Szczególne
Delegaty
1 p u b l i c c l a s s De l e g u j a c a
2 f
3 p r i v a t e d e l e g a t e o b j e c t De l e g a t ( o b j e c t param) ;
4 p r i v a t e De l e g a t d e l e g a t ;
5
6 p u b l i c o b j e c t De l e g a c j a ( o b j e c t param)
7 f
8 i f ( d e l e g a t != n u l l )
9 r e t u r n d e l e g a t ( param) ;
10
11 r e t u r n n u l l ;
12 g
13 g
Mikołaj Olszewski (WZIM SGGW) Programowanie Komponentowe Wykład #3 27 / 71
37. Rozwiazania praktyczne Szczególne
Wywołania zwrotne
1 p u b l i c c l a s s Wywolujaca
2 f
3 p r i v a t e o b j e c t param ;
4
5 p u b l i c void Ope r a c j a ( Ca l l b a c k c a l l b a c k )
6 f
7 doSomething ( ) ;
8
9 i f ( c a l l b a c k != n u l l )
10 r e t u r n c a l l b a c k . C a l l ( param) ;
11
12 r e t u r n n u l l ;
13 g
14 g
Mikołaj Olszewski (WZIM SGGW) Programowanie Komponentowe Wykład #3 28 / 71
38. Rozwiazania praktyczne Szczególne
Delegaty
1 p u b l i c c l a s s Wywolujaca
2 f
3 p r i v a t e d e l e g a t e o b j e c t Ca l l b a c k ( o b j e c t param) ;
4 p r i v a t e o b j e c t param ;
5
6 p u b l i c o b j e c t Ope r a c j a ( Ca l l b a c k c a l l b a c k )
7 f
8 doSomething ( ) ;
9
10 i f ( c a l l b a c k != n u l l )
11 r e t u r n c a l l b a c k ( param) ;
12
13 r e t u r n n u l l ;
14 g
15 g
Mikołaj Olszewski (WZIM SGGW) Programowanie Komponentowe Wykład #3 29 / 71
41. Rozwiazania praktyczne Szczególne
Domieszki
1 p u b l i c s t a t i c c l a s s SwimMixin
2 f
3 p u b l i c s t a t i c void Swim( t h i s ISwim t a r g e t )
4 f
5 // Perform Swim f u n c t i o n a l i t y on the t a r g e t
6 g
7 g
8
9 Penguin penguin = new Penguin ( ) ;
10 penguin . Swim( ) ;
Mikołaj Olszewski (WZIM SGGW) Programowanie Komponentowe Wykład #3 32 / 71
42. Rozwiazania praktyczne Szczególne
Domieszki
1 p u b l i c s t a t i c c l a s s TimeMixin
2 f
3 p u b l i c s t a t i c TimeSpan Days ( t h i s i n t days )
4 f
5 r e t u r n new TimeSpan ( days , 0 , 0 , 0) ;
6 g
7
8 p u b l i c s t a t i c DateTime FromNow( t h i s TimeSpan timeSpan )
9 f
10 r e t u r n DateTime .Now. Add ( timeSpan ) ;
11 g
12 g
Mikołaj Olszewski (WZIM SGGW) Programowanie Komponentowe Wykład #3 33 / 71
43. Rozwiazania praktyczne Szczególne
Domieszki
1 p u b l i c s t a t i c c l a s s TimeMixin
2 f
3 p u b l i c s t a t i c TimeSpan Days ( t h i s i n t days )
4 f
5 r e t u r n new TimeSpan ( days , 0 , 0 , 0) ;
6 g
7
8 p u b l i c s t a t i c DateTime FromNow( t h i s TimeSpan timeSpan )
9 f
10 r e t u r n DateTime .Now. Add ( timeSpan ) ;
11 g
12 g
1 3 . Days ( ) . FromNow( ) ;
Mikołaj Olszewski (WZIM SGGW) Programowanie Komponentowe Wykład #3 33 / 71
44. Rozwiazania praktyczne Szczególne
Leniwa inicjalizacja
1 p u b l i c c l a s s F r u i t
2 f
3 p r i v a t e s t a t i c Di c t i o n a r y<s t r i n g , Fr u i t> t y p e s = new Di c t i o n a r y<s t r i n g , Fr u i t >() ;
4 p r i v a t e s t r i n g t ype ;
56
p r i v a t e F r u i t ( S t r i n g t ype )
7 f
8 t h i s . t ype = t ype ;
9 g
10
11 p u b l i c s t a t i c F r u i t g e t F r u i t ( s t r i n g t ype )
12 f
13 F r u i t f ;
14 i f ( ! t y p e s . TryGetValue ( type , out f ) )
15 f
16 f = new F r u i t ( t ype ) ; // l a z y i n i t i a l i z a t i o n
17 t y p e s . Add ( type , f ) ;
18 g
19 r e t u r n f ;
20 g
21 g
Mikołaj Olszewski (WZIM SGGW) Programowanie Komponentowe Wykład #3 34 / 71
54. Przykład Podejscie 1 — koty za płoty
Podejscie 1
Mikołaj Olszewski (WZIM SGGW) Programowanie Komponentowe Wykład #3 44 / 71
55. Przykład Podejscie 1 — koty za płoty
Interfejs
1 p u b l i c i n t e r f a c e I C a l c u l a t o r
2 f
3 void Add ( double number ) ;
4 void Sub ( double number ) ;
5 void Mul ( double number ) ;
6 void Div ( double number ) ;
7 . . .
8
9 double Cu r r e n tVa l u e f ge t ; g
10
11 void MemoryClear ( ) ;
12 void MemoryRetrive ( ) ;
13 void MemoryStore ( ) ;
14
15 void Re s e t ( ) ;
16 g
Mikołaj Olszewski (WZIM SGGW) Programowanie Komponentowe Wykład #3 45 / 71
56. Przykład Podejscie 1 — koty za płoty
Zmodyfikowane podejscie 1 — separacja usług
Mikołaj Olszewski (WZIM SGGW) Programowanie Komponentowe Wykład #3 46 / 71
57. Przykład Podejscie 1 — koty za płoty
Separacja odpowiedzialnosci
1 p u b l i c i n t e r f a c e I C a l c u l a t i o n s
2 f
3 void Add ( double number ) ;
4 void Sub ( double number ) ;
5 void Mul ( double number ) ;
6 void Div ( double number ) ;
7 . . .
8 g
9
10 p u b l i c i n t e r f a c e IMemoryOperations
11 f
12 void MemoryClear ( ) ;
13 void MemoryRetrive ( ) ;
14 void MemoryStore ( ) ;
15
16 void Re s e t ( ) ;
17 g
18
19 p u b l i c i n t e r f a c e IDi s p l a y
20 f
21 double Cu r r e n tVa l u e f ge t ; g
22 g
Mikołaj Olszewski (WZIM SGGW) Programowanie Komponentowe Wykład #3 47 / 71
58. Przykład Podejscie 1 — koty za płoty
Ulepszony interfejs
1 p u b l i c i n t e r f a c e I C a l c u l a t i o n s
2 f
3 IEnumerable<IOp e r a t i o n> Al l owe dOp e r a t i o n s f ge t ; g
4
5 void Pe r formOpe r a t ion ( IOp e r a t i o n o p e r a t i o n , double number ) ;
6 g
7
8 p u b l i c i n t e r f a c e IOp e r a t i o n
9 f
10 double Ca l c u l a t e ( double number1 , double number2 ) ;
11 g
Mikołaj Olszewski (WZIM SGGW) Programowanie Komponentowe Wykład #3 48 / 71
59. Przykład Podejscie 1 — koty za płoty
Implementacja operacji
1 c l a s s Add : IOp e r a t i o n
2 f
3 p u b l i c double Ca l c u l a t e ( double number1 , double number2 )
4 f
5 r e t u r n number1 + number2 ;
6 g
7 g
Mikołaj Olszewski (WZIM SGGW) Programowanie Komponentowe Wykład #3 49 / 71
60. Przykład Podejscie 1 — koty za płoty
Implementacja kalkulatora
1 p u b l i c c l a s s C a l c u l a t o r : IDi s p l a y , I C a l c u l a t i o n s ,
2 IMemoryOperations
3 f
4 p r i v a t e double c u r r e n tVa l u e = 0 ;
5 p u b l i c double Cu r r e n tVa l u e
6 f
7 ge t f r e t u r n c u r r e n tVa l u e ; g
8 g
9
10 p r i v a t e L i s t <IOp e r a t i o n> o p e r a t i o n s = new L i s t <IOp e r a t i o n>
11 f
12 new Add ( ) , new Sub ( ) , new Mul ( ) , new Div ( ) , . . .
13 g
14 p u b l i c IEnumerable<IOp e r a t i o n> Al l owe dOp e r a t i o n s
15 f
16 ge t f r e t u r n o p e r a t i o n s . AsReadOnly ( ) ; g
17 g
18
19 p u b l i c void Pe r formOpe r a t ion ( IOp e r a t i o n o p e r a t i o n , double number )
20 f
21 c u r r e n tVa l u e = o p e r a t i o n . Ca l c u l a t e ( c u r r e n tVa l u e , number ) ;
22 g
23
24 . . .
Mikołaj Olszewski (WZIM SGGW) Programowanie Komponentowe Wykład #3 50 / 71
61. Przykład Podejscie 1 — koty za płoty
Implementacja kalkulatora c.d.
1 p u b l i c c l a s s C a l c u l a t o r : IDi s p l a y , I C a l c u l a t i o n s ,
2 IMemoryOperations
3 f
4 . . .
5
6 p r i v a t e double memory = 0 ;
7
8 p u b l i c void MemoryClear ( ) f memory = 0 ; g
9 p u b l i c void MemoryRetrive ( ) f c u r r e n tVa l u e = memory ; g
10 p u b l i c void MemoryStore ( ) f memory = c u r r e n tVa l u e ; g
11
12 p u b l i c void Re s e t ( )
13 f
14 c u r r e n tVa l u e = 0 ;
15 memory = 0 ;
16 g
17 g
Mikołaj Olszewski (WZIM SGGW) Programowanie Komponentowe Wykład #3 51 / 71
63. Przykład Podejscie 2 — separacja implementacji usług
Implementacja interfejsów
1 c l a s s Di s p l a y : IDi s p l a y
2 f
3 p r i v a t e r e ado nl y Accumulator ;
4
5 Di s p l a y ( Accumulator a c cumul a tor )
6 f
7 t h i s . a c cumul a tor = a c cumul a tor ;
8 g
9
10 p u b l i c double Cu r r e n tVa l u e
11 f
12 ge t f r e t u r n a c cumul a tor . GetValue ( ) ; g
13 g
14 g
Mikołaj Olszewski (WZIM SGGW) Programowanie Komponentowe Wykład #3 53 / 71
64. Przykład Podejscie 2 — separacja implementacji usług
Implementacja interfejsów c.d.
1 c l a s s C a l c u l a t i o n s : I C a l c u l a t i o n s
2 f
3 p r i v a t e r e ado nl y Accumulator ;
4 C a l c u l a t i o n s ( Accumulator a c cumul a tor )
5 f
6 t h i s . a c cumul a tor = a c cumul a tor ;
7 g
8
9 p r i v a t e L i s t <IOp e r a t i o n> o p e r a t i o n s = new L i s t <IOp e r a t i o n>
10 f
11 new Add ( ) , new Sub ( ) , new Mul ( ) , new Div ( ) , . . .
12 g
13 p u b l i c IEnumerable<IOp e r a t i o n> Al l owe dOp e r a t i o n s
14 f
15 ge t f r e t u r n o p e r a t i o n s . AsReadOnly ( ) ; g
16 g
17
18 p u b l i c void Pe r formOpe r a t ion ( IOp e r a t i o n o p e r a t i o n , double number )
19 f
20 a c cumul a tor . Se tVa lue (
21 o p e r a t i o n . Ca l c u l a t e ( a c cumul a tor . GetValue ( ) , o p e r a t i o n , number )
22 ) ;
23 g
24 g
Mikołaj Olszewski (WZIM SGGW) Programowanie Komponentowe Wykład #3 54 / 71
65. Przykład Podejscie 2 — separacja implementacji usług
Implementacja interfejsów c.d.
1 c l a s s MemoryOperations : IMemoryOperations
2 f
3 p r i v a t e double memory = 0 ;
4 p r i v a t e r e ado nl y Accumulator a c cumul a tor ;
5
6 MemoryOperations ( Accumulator a c cumul a tor )
7 f
8 t h i s . a c cumul a tor = a c cumul a tor ;
9 g
10
11 p u b l i c double MemoryRetrive ( ) f r e t u r n memory ; g
12
13 p u b l i c void MemoryStore ( double newMemory ) f memory = newMemory ; g
14
15 p u b l i c void MemoryClear ( ) f memory = 0 ; g
16
17 p u b l i c void Re s e t ( )
18 f
19 MemoryClear ( ) ;
20 a c cumul a tor . Cl e a r ( ) ;
21 g
22 g
Mikołaj Olszewski (WZIM SGGW) Programowanie Komponentowe Wykład #3 55 / 71
66. Przykład Podejscie 2 — separacja implementacji usług
Klasa pomocnicza
1 c l a s s Accumulator
2 f
3 p r i v a t e double v a l u e = 0 ;
4
5 double GetValue ( ) f r e t u r n v a l u e ; g
6
7 void Se tVa lue ( double newValue ) f v a l u e = newValue ; g
8
9 void Cl e a r ( ) f v a l u e = 0 ; g
10 g
Mikołaj Olszewski (WZIM SGGW) Programowanie Komponentowe Wykład #3 56 / 71
67. Przykład Podejscie 2 — separacja implementacji usług
Implementacja kalkulatora z delegacjami
1 p u b l i c c l a s s C a l c u l a t o r : IDi s p l a y , I C a l c u l a t i o n s ,
2 IMemoryOperations
3 f
4 p r i v a t e Accumulator a c cumul a tor = new Accumulator ( ) ;
5 p r i v a t e IDi s p l a y d i s p l a y = new Di s p l a y ( a c cumul a tor ) ;
6 p r i v a t e I C a l c u l a t i o n s c a l c u l a t i o n s = new C a l c u l a t i o n s ( a c cumul a tor
) ;
7 p r i v a t e IMemoryOperations memOpers = new MemoryOperations (
a c cumul a tor ) ;
8
9 p u b l i c double Cu r r e n tVa l u e
10 f
11 ge t f r e t u r n d i s p l a y . Cu r r e n tVa l u e g
12 g
13 p u b l i c IEnumerable<IOp e r a t i o n> Al l owe dOp e r a t i o n s
14 f
15 ge t f r e t u r n c a l c u l a t i o n s . Al l owe dOp e r a t i o n s ; g
16 g
17 p u b l i c void Pe r formOpe r a t ion ( IOp e r a t i o n o p e r a t i o n , double number )
18 f
19 a c cumul a tor . Se tVa lue (
20 c a l c u l a t i o n s . Ca l c u l a t e ( a c cumul a tor . GetValue ( ) , o p e r a t i o n ,
number )
Mikołaj Olszewski (WZIM SGGW) Programowanie Komponentowe Wykład #3 57 / 71
21 ) ;
68. Przykład Podejscie 2 — separacja implementacji usług
Implementacja kalkulatora z delegacjami c.d.
1 p u b l i c c l a s s C a l c u l a t o r : IDi s p l a y , I C a l c u l a t i o n s ,
2 IMemoryOperations
3 f
4 . . .
5
6 p u b l i c void MemoryClear ( )
7 f
8 memOpers . Cl e a r ( ) ;
9 g
10 p u b l i c void MemoryRetrive ( )
11 f
12 memOpers . Re t r i v e ( ) ;
13 g
14 p u b l i c void MemoryStore ( )
15 f
16 memOpers . St o r e ( ) ;
17 g
18
19 p u b l i c void Re s e t ( )
20 f
21 memOpers . Re s e t ( ) ;
22 g
23 g
Mikołaj Olszewski (WZIM SGGW) Programowanie Komponentowe Wykład #3 58 / 71
70. Przykład Podejscie 3 — refaktoryzacja
Uwspólnienie pamieci
1 c l a s s Re g i s t e r
2 f
3 p r i v a t e double v a l u e = 0 ;
4
5 double Re t r i v e ( ) f r e t u r n v a l u e ; g
6
7 void St o r e ( double v a l u e ) f t h i s . v a l u e = v a l u e ; g
8
9 void Cl e a r ( ) f v a l u e = 0 ; g
10 g
Mikołaj Olszewski (WZIM SGGW) Programowanie Komponentowe Wykład #3 60 / 71
71. Przykład Podejscie 3 — refaktoryzacja
Implementacja interfejsów c.d.
1 c l a s s MemoryOperations : IMemoryOperations
2 f
3 p r i v a t e Re g i s t e r accumulator , memory ;
4
5 MemoryOperations ( Re g i s t e r accumulator , Re g i s t e r memory )
6 f
7 t h i s . a c cumul a tor = a c cumul a tor ;
8 t h i s . memory = memory ;
9 g
10
11 p u b l i c double MemoryRetrive ( ) f r e t u r n memory . Re t r i v e ( ) ; g
12
13 p u b l i c void MemoryStore ( double v a l u e ) f memory . St o r e ( v a l u e ) ; g
14
15 p u b l i c void MemoryClear ( ) f memory . Cl e a r ( ) ; g
16
17 p u b l i c void Re s e t ( )
18 f
19 a c cumul a tor . Cl e a r ( ) ;
20 memory . Cl e a r ( ) ;
21 g
22 g
Mikołaj Olszewski (WZIM SGGW) Programowanie Komponentowe Wykład #3 61 / 71
72. Przykład Podejscie 3 — refaktoryzacja
Implementacja kalkulatora jako dostawcy usług
1 p u b l i c c l a s s C a l c u l a t o r
2 f
3 p r i v a t e Re g i s t e r a c cumul a tor = new Re g i s t e r ( ) ;
4 p r i v a t e Re g i s t e r memory = new Re g i s t e r ( ) ;
5
6 p r i v a t e IDi s p l a y d i s p l a y = new Di s p l a y ( a c cumul a tor ) ;
7 p r i v a t e I C a l c u l a t i o n s c a l c u l a t i o n s = new C a l c u l a t i o n s ( a c cumul a tor
) ;
8 p r i v a t e IMemoryOperations memOpers = new MemoryOperations (
accumulator , memory ) ;
9
10 p u b l i c IDi s p l a y Ge t IDi s p l a y ( ) f r e t u r n d i s p l a y ; g
11
12 p u b l i c I C a l c u l a t i o n s Ge t I C a l c u l c a t i o n s ( ) f r e t u r n c a l c u l a t i o n s ; g
13
14 p u b l i c IMemoryOperations GetIMemoryOperations f r e t u r n memOpers ;
g
15 g
Mikołaj Olszewski (WZIM SGGW) Programowanie Komponentowe Wykład #3 62 / 71
73. Przykład Konkluzja — poczatki frameworka
Interfejs komponentu
1 p u b l i c i n t e r f a c e IComponent
2 f
3 IEnumerable<Type> P r o v i d e d I n t e r f a c e s f ge t ; g
4 IEnumerable<Type> R e q u i r e d I n t e r f a c e s f ge t ; g
5
6 o b j e c t Ge t I n t e r f a c e (Type t ype ) ;
7 T Ge t I n t e r f a c e <T>() where T : c l a s s ;
8 g
Mikołaj Olszewski (WZIM SGGW) Programowanie Komponentowe Wykład #3 63 / 71
74. Przykład Konkluzja — poczatki frameworka
Abstrakcyjny komponent
1 p u b l i c a b s t r a c t c l a s s AbstractComponent : IComponent
2 f
3 p r i v a t e Di c t i o n a r y<Type , Func<obj e c t>> p r o v i d e d I n t e r f a c e s ;
4 p r i v a t e L i s t <Type> r e q u i r e d I n t e r f a c e s ;
5
6 p u b l i c AbstractComponent ( )
7 f
8 p r o v i d e d I n t e r f c a c e s = new Di c t i o n a r y<Type , Func<obj e c t >>() ;
9 r e q u i r e d I n t e r f c a c e s = new L i s t <Type>() ;
10 g
11
12 p u b l i c IEnumerable<Type> P r o v i d e d I n t e r f a c e s
13 f
14 ge t f r e t u r n p r o v i d e d I n t e r f a c e s . Keys ; g
15 g
16
17 p u b l i c IEnumerable<Type> R e q u i r e d I n t e r f a c e s
18 f
19 ge t f r e t u r n r e q u i r e d I n t e r f a c e s . AsReadOnly ( ) ; g
20 g
Mikołaj Olszewski (WZIM SGGW) Programowanie Komponentowe Wykład #3 64 / 71
75. Przykład Konkluzja — poczatki frameworka
Abstrakcyjny komponent c.d.
1 p u b l i c o b j e c t Ge t I n t e r f a c e (Type t ype )
2 f
3 i f ( p r o v i d e d I n t e r f c a c e s . ContainsKey ( t ype ) )
4 r e t u r n p r o v i d e d I n t e r f a c e s [ t ype ] ( ) ;
5 r e t u r n n u l l ;
6 g
7
8 p u b l i c T Ge t I n t e r f a c e <T>() where T : c l a s s
9 f
10 Type t ype = t ypeo f (T) ;
11 r e t u r n Ge t I n t e r f a c e ( t ype ) as T;
12 g
Mikołaj Olszewski (WZIM SGGW) Programowanie Komponentowe Wykład #3 65 / 71
76. Przykład Konkluzja — poczatki frameworka
Abstrakcyjny komponent c.d.
1 p u b l i c void R e g i s t e r P r o v i d e d I n t e r f a c e (Type type , Func<obj e c t>
p r o v i d e r )
2 f
3 i f ( ! t ype . I s I n t e r f a c e )
4 throw new ArgumentException (
5 s t r i n g . Format ( ” R e g i s t e r i n g t ype f0g i s not an i n t e r f a c e ” ,
t ype ) , ” t ype ” ) ;
6 o b j e c t ob j = p r o v i d e r ( ) ;
7 i f ( ! t ype . I s I n s t a n c eOfTy p e ( o bj ) )
8 throw new ArgumentException (
9 s t r i n g . Format ( ” R e g i s t e r i n g p r o v i d e r does not p r o v i d e o b j e c t
impl ement ing f0g i n t e r f a c e ” , t ype ) , ” p r o v i d e r ” ) ;
10 p r o v i d e d I n t e r f c a c e s [ t ype ] = p r o v i d e r ;
11 g
12
13 p u b l i c void R e g i s t e r R e q u i r e d I n t e r f a c e (Type t ype )
14 f
15 i f ( ! t ype . I s I n t e r f a c e )
16 throw new ArgumentException (
17 s t r i n g . Format ( ” R e g i s t e r i n g t ype f0g i s not an i n t e r f a c e ” ,
t ype ) , ” t ype ” ) ;
18 r e q u i r e d I n t e r f c a c e s . Add ( t ype ) ;
19 g
20 g
Mikołaj Olszewski (WZIM SGGW) Programowanie Komponentowe Wykład #3 66 / 71
77. Przykład Konkluzja — poczatki frameworka
Komponent kalkulatora
1 p u b l i c c l a s s C a l c u l a t o r : AbstractComponent
2 f
3 p r i v a t e Re g i s t e r a c cumul a tor = new Re g i s t e r ( ) ;
4 p r i v a t e Re g i s t e r memory = new Re g i s t e r ( ) ;
5
6 p r i v a t e IDi s p l a y d i s p l a y = new Di s p l a y ( a c cumul a tor ) ;
7 p r i v a t e I C a l c u l a t i o n s c a l c u l a t i o n s = new C a l c u l a t i o n s ( a c cumul a tor
) ;
8 p r i v a t e IMemoryOperations memOpers = new MemoryOperations (
accumulator , memory ) ;
9
10 p u b l i c C a l c u l a t o r ( )
11 f
12 R e g i s t e r P r o v i d e d I n t e r f a c e (
13 t ypeo f ( IDi s p l a y ) , ( ) => d i s p l a y ) ;
14 R e g i s t e r P r o v i d e d I n t e r f a c e (
15 t ypeo f ( I C a l c u l a t i o n s ) , ( ) => c a l c u l a t i o n s ) ;
16 R e g i s t e r P r o v i d e d I n t e r f a c e (
17 t ypeo f ( IMemoryOperations ) , ( ) => memOpers ) ;
18 g
19 g
Mikołaj Olszewski (WZIM SGGW) Programowanie Komponentowe Wykład #3 67 / 71
79. Podsumowanie
Podsumowanie
Dobre praktyki zarówno w OOP jak i w komponentach
Podejscie komponentowe jest nieco odmienne
Programowanie obiektowe podstawa
Sztuczki i kruczki
Wzorce projektowe szeroko wykorzystywane
Mikołaj Olszewski (WZIM SGGW) Programowanie Komponentowe Wykład #3 69 / 71
80. Podsumowanie
Do domu
Przyswoic zasady SOLID
Przyswoic wzorce projektowe
Zapoznac sie i zrozumiec przykłady z wykładu
Przeczytac 1. rozdział z „Developer’s Guide to Microsoft Unity”
Mikołaj Olszewski (WZIM SGGW) Programowanie Komponentowe Wykład #3 70 / 71