Ơn Nghĩa Sinh Thành (edit)
Beginning SOLID Principles and Design Patterns for ASP.NET Developers
https://www.apress.com/gp/book/9781484218471
https://link.springer.com/book/10.1007%2F978-1-4842-1848-8
https://link.springer.com/content/pdf/bfm%3A978-1-4842-1848-8%2F1.pdf
https://github.com/Apress/beg-solid-principles-design-patterns-for-asp.net-devs
- Overview of SOLID Principles and Design Patterns
- SOLID Principles
- Creational Patterns: Singleton, Factory Method, and Prototype
- Creational Patterns: Abstract Factory and Builder
- Structural Patterns: Adapter, Bridge, Composite, and Decorator
- Structural Patterns: Façade, Flyweight, and Proxy
- Behavioral Patterns: Chain of Responsibility, Command, Interpreter, and Iterator
- Behavioral Patterns: Mediator, Memento, and Observer
- Behavioral Patterns: State, Strategy, Template Method, and Visitor
- Patterns of Enterprise Application Architecture: Repository, Unit of Work, Lazy Load, and Service Layer
- JavaScript Code-Organization Techniques and Patterns
SOLID Principlesfor Cloud Native Applications
OOP: Classes and Objects, Abstraction, Encapsulation, Inheritance, Abstract Classes and Interfaces, Polymorphism, Polymorphic Behavior Through Inheritance, Polymorphic Behavior Through Interfaces 1) SOLID Principles and Design Patterns + Single Responsibility Principle + Open/Closed Principle + Liskov Substitution Principle + Interface Segregation Principle + Dependency Inversion Principle 2) Gang of Four (GoF) design patterns + Creational patterns + Structural patterns + Behavioral patterns 3) Patterns of Enterprise Application Architecture (P of EAA) Categorization of P of EAA: + Domain-logic patterns + Data-source architectural patterns + Object-relational behavioral patterns + Object-relational structural patterns + Object-relational metadata-mapping patterns + Web presentation patterns + Distribution patterns + Offline concurrency patterns + Session-state patterns + Base patterns 4) JavaScript patterns Samples: + System.IO: GZipStream in .NET Framework using the Decorator design pattern. + System.Convert.ToInt32("123") using the Factory pattern. + The foreach loop of C# that iterates through a collection is an example of the Iterator pattern. + The Entity Framework implements the Repository and Unit of Work patterns. Lazy Initialization: System.Lazy There are four lifetime modes for a service being injected: + Singleton: An object of a service is created and supplied to all the requests to that service. So, basically all requests get the same object to work with. + Scoped: An object of a service is created for each and every request. So, each request gets its a new instance of a service to work with. + Transient: An object of a service is created every time an object is requested. + Instance: In this case you are responsible for creating an object of a service. The DI framework then uses that instance in the singleton mode mentioned earlier. P of EAA: four important patterns: repository, unit of work, lazy load, and service layer. JavaScript: object literal, function object, prototype, and IIFE 1) Create an Object via Object literals: var employee = { "employeeID": 1, "firstName": "Nancy", "lastName": "Davolio", "display": function () { alert("#" + this.employeeID + " - " + this.firstName + " " + this.lastName); } }; var employee = {}; employee.employeeID = 1; employee.firstName = "Nancy"; employee.lastName = "Davolio"; employee.display = function () { alert("#" + this.employeeID + " - " + this.firstName + " " + this.lastName); }; 2) Create an Object via Function objects: var employee = function () { this.employeeID = 0; this.firstName = ""; this.lastName = ""; this.display = function () { alert("#" + this.employeeID + " - " + this.firstName + " " + this.lastName); } var emp = new employee(); emp.employeeID = 1; emp.firstName = "Nancy"; emp.lastName = "Davolio"; emp.display(); Immediately Invoked Function Expressions (IIFE): (function () { alert("Hello World!"); })(); jQuery Plugin and IIFE (function ($) { $.fn.decorate = function (settings) { //plugin code here } })(jQuery); JavaScript patterns + Namespace Pattern + Module Pattern + Revealing Module Pattern + Sandbox Pattern GoF patterns: + Singleton pattern (creational) + Façade pattern (structural) + Observer pattern (behavioral) Singleton in JavaScript: Way 1 var ThemeSettings = function () { var instance = this; this.colorTheme = "Office"; this.fontTheme = "Modern"; this.layoutTheme = "SideBySide"; ThemeSettings = function () { return instance; } } var settings1 = new ThemeSettings(); var settings2 = new ThemeSettings(); alert("Is ThemeSettings instance same? " + (settings1 === settings2)); settings2.colorTheme = "Nature"; alert("settings1.colorTheme is " + settings1.colorTheme); Singleton in JavaScript: Way 2 var ThemeSettings = (function () { var instance; function createInstance() { var settings = new Object(); settings.colorTheme = "Office"; settings.fontTheme = "Modern"; settings.layoutTheme = "SideBySide"; return settings; } return { getInstance: function () { if (!instance) { instance = createInstance(); } return instance; } }; })(); Façade pattern var AddressDetails = function () { this.validate = function () { //complex code here return true; } } var BankDetails = function () { this.validate = function () { //complex code here return true; } } var EmploymentDetails = function () { this.validate = function () { //complex code here return true; } } var OrderProcessor = function () { //constructor code here } OrderProcessor.prototype.validateDetails = function () { var addresss = new AddressDetails(); var bank = new BankDetails(); var employment = new EmploymentDetails(); var result = true; if (!addresss.validate()) { result = false; } else if (!bank.validate()) { result = false; } else if (!employment.validate()) { result = false; } return result; } var app = new OrderProcessor(); var status = app.validateDetails(); alert("Are details valid? " + status); Observer Pattern function BlogComment() { this.observers = []; } BlogComment.prototype = { subscribe: function (fn) { this.observers.push(fn); }, unsubscribe: function (fn) { this.observers = this.handlers.filter( function (item) { if (item !== fn) { return item; } } ); }, broadcast: function (data) { this.observers.forEach(function (item) { item.call(null, data); }); } }
<h2>Comments:</h2>
<textarea cols="40" rows="4" id="text1"></textarea>
<br />
<div id="div1"></div>
<div id="div2"></div>
$(document).ready(function () { var Subscriber1 = function (data) { $("#div1").html(data); }; var Subscriber2 = function (data) { $("#div2").html("<h4>Count : " + data.length + "</h4>"); }; var comment = new BlogComment(); comment.subscribe(Subscriber1); comment.subscribe(Subscriber2); }); $("#text1").keyup(function () { comment.broadcast($("#text1").val()); }); + Model-View-Controller (MVC) + Model-View-View Model (MVVM) + Model-View-Whatever (MVW) http://www.devx.com/ http://dotnetguts.blogspot.com/2007/11/design-patterns-in-aspnet-20.html http://file.allitebooks.com/20160426/Beginning%20SOLID%20Principles%20and%20Design%20Patterns%20for%20ASP.NET%20%20Developers.pdf MVC Pattern MVP Pattern Provider Pattern Adapter Pattern Service Agent Pattern Proxy Pattern Broker Pattern Repository Pattern Singleton Pattern ASP.NET and the Provider Pattern ASP.NET and the Adapter Pattern Implementing the Repository Pattern Implementing the Singleton Pattern Code for Published Articles http://www.daveandal.net/da/books/misc/articles.htm Code and Resources For Our Books http://www.daveandal.net/da/books/misc/default.htm Tips http://www.devx.com/tips/ http://www.devx.com/DevX/tip-extending-simple-enum-values-to-be-composite.html http://www.devx.com/tips/dot-net/c-sharp/block-and-unblock-the-internet-on-a-users-computer-using-c-170717074512.html