Скачать презентацию Design Patterns или приемы расширяемого программирования Часть 2 Скачать презентацию Design Patterns или приемы расширяемого программирования Часть 2

ООП приемы программирования, часть 2.pptx

  • Количество слайдов: 9

Design Patterns, или приемы расширяемого программирования Часть 2. Приемы программирования, не относящиеся к Go. Design Patterns, или приемы расширяемого программирования Часть 2. Приемы программирования, не относящиеся к Go. F

План действий 1. 2. 3. 4. 5. Lazy loading Object pool Publish-subscribe (Messenger) Auto План действий 1. 2. 3. 4. 5. Lazy loading Object pool Publish-subscribe (Messenger) Auto mapper Fluent interface

Lazy loading private string _log. Path; public string Log. Path { get { if Lazy loading private string _log. Path; public string Log. Path { get { if (_log. Path == null) { _log. Path = _configurator. Get. Key. Value(Log. Path. Key); } return _log. Path; } }

Lazy loading public class Lazy<T> where T : class { private T _value; private Lazy loading public class Lazy where T : class { private T _value; private readonly Func _factory; public Lazy() { _factory = Activator. Create. Instance; } public Lazy(Func factory) { Guard. Not. Null(factory, "factory"); _factory = factory; } public T Value { get { return _value ? ? (_value = _factory()); } } }

Object pool Initialized object Client 1. Acquire 2. Use 3. Release Initialized object. . Object pool Initialized object Client 1. Acquire 2. Use 3. Release Initialized object. . . Client Initialized object Pool

Publish-subscribe (Messenger) Subscriber Publisher Messenger New. Customer. Added Items. List. Updated Subscriber Publisher Subscriber Publish-subscribe (Messenger) Subscriber Publisher Messenger New. Customer. Added Items. List. Updated Subscriber Publisher Subscriber

Auto mapper public class Holdings. Data { public int ID { get; set; } Auto mapper public class Holdings. Data { public int ID { get; set; } public string Ticker { get; set; } public string Name { get; set; } public string Trading. Country { get; set; } public string Major. Asset. Type { get; set; } public double Shares { get; set; } public string Local. Currency { get; set; } public double Local. Price { get; set; } } public class Holdings. Data. View. Model : View. Model. Base { public int ID { get; set; } public string Ticker { get; set; } public string Name { get; set; } public string Trading. Country { get; set; } public string Major. Asset. Type { get; set; } public double Shares { get; set; } public string Local. Currency { get; set; } public double Local. Price { get; set; } // View. Model specific public bool Is. Selected { get; set; }. . . var holdings = new Holdings. Data() { /*initialization*/ }; // Data Access Layer. . . holdings. View. Model = new Holdings. Data. View. Model(); // Presentation Layer holdings. View. Model. Map. From(holdings);

Fluent interface public class Customer. Validator: Validator<Customer> { public Customer. Validator() { Rule. For(customer Fluent interface public class Customer. Validator: Validator { public Customer. Validator() { Rule. For(customer => customer. Surname). Not. Empty(). With. Message( "Please specify a surname"); Rule. For(customer => customer. Name). Not. Empty(). With. Message( "Please specify a first name"); Rule. For(customer => customer. Company). Not. Null(); Rule. For(customer => customer. Discount). Not. Equal( 0). When(customer => customer. Has. Discount); Rule. For(customer => customer. Address). Length( 20, 250); Rule. For(customer => customer. Postcode ). Must(Be. AValid. Postcode). With. Message("Please specify a valid postcode"); } private bool Be. AValid. Postcode(string postcode) { // custom postcode validation logic goes here } } Customer customer = new Customer() { /*initialization*/ }; Customer. Validator validator = new Customer. Validator(customer); Validation. Result results = validator. Validate( "Surname");

THANKS FOR YOUR ATTENTION! ANY QUESTIONS? Design Patterns, или приемы расширяемого программирования Author: THANKS FOR YOUR ATTENTION! ANY QUESTIONS? Design Patterns, или приемы расширяемого программирования Author: