While working on real time projects, we normally create so many intefaces, clasess and using unmanged resources like DB connection, files operation etc. To manage performance of the application these resources should be freed on time. We can cleanup those resources using Dispose and Finalize methods. Class instances encapsulate control over resources that are not managed by the runtime, such as window handles (HWND), database connections, and so on. Therefore, we should provide both an explicit and an implicit way to free those resources. We should provide implicit control by implementing the protected Finalize on an object.The Finalize method is called when our object is garbage collected and…
Author: Dhanik Lal Sahni
Cohesion and Coupling are essences of a good design process. The system should be decomposed into many modules to make it manageable for system changes. Projects which are well-designed are rarely in trouble with system changes. These changes should be properly reviewed and recognized. Read the first part of this topic here. Coupling Coupling is the measure of the degree of interdependence between modules. Two modules with high coupling are strongly interconnected and thus, dependent on each other. Two modules with low coupling are not dependent on one another. Lossely coupled systems are made up of modules which are relatively…
Cohesion and Coupling are essences of a good design process. The system should be decomposed into many modules to make it manageable in system changes. Projects which are well-designed are rarely in trouble in system changes. These changes should be properly reviewed and recognized. If software system is not properly modularized, then it will create problem when sytems changes are required. A good software design help in clean decomposition of a problem into modules and arrangement of these modules. Therefor system analyst, should must design application with goal of high cohesion and low coupling. As this topic is big for…
We have two approaches to build web applications in current time: Traditional web applications and Single page applications (SPAs). Traditional web applications perform most of the application logic on the server side whereas single page applications (SPAs) perform most of the user interface logic in a web browser. Single Page Application communicate with the web server primarily using web APIs. When to Choose Traditional Web Pages We can use below factor to use Traditional Web Pages. 1. Application is simple and very less user interaction Many web application has very less user interaction like google.com, where user only search any query and they get result in result box…
The Liskov Substitution Principle states that subtypes must be substitutable for their base types. In order to substitute work, child class must not Remove base class behavior Violate base class invariants In general calling code should not know they are different from base types. LSP suggests that IS-A relationship should be replaced with IS-SUBSTITUTABLE-FOR. Let us take example of any web site subscription. Web site offer two types of customer, one is free and other is paid customer. So we will be having an interface like below public interface ICustomer { string CustomerName { set; get; } int CustomerCode { set; get; }…
Software entities (classes, modules, functions, etc.) should be open for extension, but closed for modification. According to this principle, component should be Open to ExtensionNew behavior can be added in the future. Closed to Modification Changes to source code is not required. Based on above statement, software entities should change behavior without changing code. For this, we have to use abstraction to implement behavior. In .NET we can use Interface and Abstract class to implement abstraction. Let us see an example of e-commerce application to calculate cart’s total amount. public class OrderItem { public string StockKeepingUnit { get; set; }…
According to Wikipedia the Dependency Inversion Principle (popularized by Robert Martin) states that: High Level Modules should not be depend upon low level modules. Both should depend upon abstractions. Abstraction should not depend upon details. Details should depend upon abstraction. In application architecture, UI is always on top level. All request goes from UI to business layer and then database layer. Database layer connects with database and fetch required data. Â When we define Dependency Inversion Principle in above architectute, The presentation layer defines the abstractions it needs to interact with an business layer and the business layer defines the…
SRP states, “An object should have only one reason to change”. If an object has more than one reason to change then it has more than one responsibility and is in violation of SRP. An object should have one and only one reason to change. Let us take example of below code, where XML file with product information is parsed and displayed on screen. FileDialogReader.Filter = “XML Document (*.xml)|*.xml|All Files (*.*)|*.*”; var result = FileDialogReader.ShowDialog(); if (result == DialogResult.OK) { txtFileName.Text = FileDialogReader.FileName; lstProduct.Items.Clear(); var fileName = txtFileName.Text; using (var fs = new FileStream(fileName, FileMode.Open)) { var reader = XmlReader.Create(fs);…
SOLID Design Principle is a collection of best-practice,object-oriented design principles which can be applied to your application design. This allow us to accomplish various desirable goals such as loose-coupling, higher maintainability. SOLID is an acronym where: (S)RP: Single Responsibility Principle There should never be more than one reason to change any class. (O)CP: Open Closed Principle Software Entities (Classes, Modules, Functions, etc. ) should be open for extension but closed for any modification. (L)SP: Liskov Substitution Principle Function that use objects of base clasesses must be able to use objects of other dervied class wihout knowing it. (I)SP: Interface Segregation…
Singleton Design Pattern is used when we want to ensure that only one object of a particular class need to be created. All other objects will refer that object to get values. This pattern create object so it falls under Creation Pattern of Gang Of Four design patterns. Condition for Singleton Design Pattern: Singleton Design Pattern need to be implemented where below three requirements are satisfied Controls concurrent access to a shared resource Access to the shared resource will be requested from multiple, disparate parts of the system There can only be one object of class Some Example where we can use Singleton Design Pattern:…