DoubleDispatch

To understand Double Dispatch, understanding of Overloading and Overriding is must. I already talked about Overloading and Overriding in post Overloading & Overriding. One level of virtual dispatching derived types override a base types: as shown below class Farms { public virtual void Irrigation() { Console.WriteLine("Farm Type"); } } class WheatFarm : Farms { public override void Irrigation() { Console.WriteLine("WheatFarm"); } } class RicaFarm : WheatFarm { public override void Irrigation() { Console.WriteLine("RicaFarm"); } } static void Main(string[] args) { var a = new Farms(); var b = new WheatFarm(); var c = new RicaFarm(); a.Irrigation(); b.Irrigation(); c.Irrigation(); } //output Farm Type WheatFarm RicaFarm Two level of virtual dispatching (Double Dispatch) This concept is used in Visitor Design Pattern. use polymorphic static binding technique to ensure that proper overload is called class Crop { public virtual void CropName(CropWatering obj) { obj.WaterSupply(this); } } class Wheat : Crop { public override void CropName(CropWatering obj) { obj.WaterSupply(this); } } /* An example of overloading (Method with same name but different parameter type) * */ class CropWatering { public virtual void WaterSupply(Crop crop) { Console.WriteLine("CropWatering working on type Crop"); } public virtual void WaterSupply(Wheat wheat) { Console.WriteLine("CropWatering working on type Wheat"); } } class CropWatringSpring : CropWatering { public override void WaterSupply(Crop crop) { Console.WriteLine("CropWatringSpring working on type Crop"); } public override void WaterSupply(Wheat wheat) { Console.WriteLine("CropWatringSpring working on type Wheat"); } } static void Main(string[] args) { Crop crop = new Crop(); Wheat wheat = new Wheat(); CropWatering cropWatering = new CropWatering(); crop.CropName(cropWatering); wheat.CropName(cropWatering); CropWatringSpring cropWatringSpring = new CropWatringSpring(); crop.CropName(cropWatringSpring); wheat.CropName(cropWatringSpring); } //output CropWatering working on type Crop CropWatering working on type Wheat CropWatringSpring working on type Crop CropWatringSpring working on type Wheat Reference

December 28, 2020 · 2 min · 282 words

Overloading & Overriding

To learn about Single & Double Dispatch, many design patterns, we need to understand Overloading and Overriding. Overloading Overloading is compile-time polymorphism. The methods/functions with same name but different number/type parameters are example of Overloading. As Overloading is compile-time, means during run-time the base type is considered. Example: class Crop { public virtual void CropName() { Console.WriteLine("Hey, My type is Crop"); } } class Wheat : Crop { public override void CropName() { Console.WriteLine("Hey, My type is Wheat"); } } /* An example of overloading (Method with same name but different parameter type) * */ class CropWatering { public void WaterSupply(Crop crop) { Console.WriteLine("I am working on type Crop"); } public void WaterSupply(Wheat wheat) { Console.WriteLine("I am working on type Wheat"); } } In main, If I create an object of type Crop and Wheat, an expected result will appear in console. ...

December 15, 2020 · 2 min · 364 words

Book Summary: Don’t make me think - Steve Krug

The book “Don’t make me think” is written by Steve Krug. This is the first book that I read about UX(User Experience Design) design. This book is concise and has four sections. The “guiding principles” talks about not puzzling the user to find required content. These principles guide to omit needless content, using conventions, images and explains the web page scanning habit of user (not reading complete content). The section “Things you need to get right” has content to design navigation that helps user to find their way. The big bang theory of web design is about designing home page, using tag lines (nothing beats a good tagline), welcome blurb and testing home page usability. The section “Making sure you got them right” is all about usability testing. Resolving conflicting thoughts between developers, designers, marketing and project managers, this section also talks about usability testing on 10 cents a day. Focusing on early usability tests, do it yourself usability testing and how often, this section importantly explains feedback loop. Finally, this section has guidance about “deciding what to fix” from feedback. ...

December 14, 2020 · 2 min · 312 words