Skip to main content

Posts

Showing posts from April, 2020

Design Patterns

A design pattern provides a general reusable solution for the common problems occurs in software design. Design Patterns are programming language independent strategies for solving a common problem. that means a design pattern represents an idea, your code more flexible, reusable and maintainable 🍥. Creational design patterns : creational design patterns are concerned with the ways of creating an object. 1. Factory Method: Define an interface or abstract class for creating an object but let the subclasses decide which class to instantiate 2. Abstract Factory: Define an interface or abstract class for creating families of related (or dependent) objects but without specifying their concrete sub-classes 3. Builder: Construct a complex object from simple objects using a step-by-step approach 4. Object Pool: Avoid expensive acquisition and release of resources by recycling objects that are no longer in use 5. Prototype: A fully initialized instance to...

Find distance between two points

The haversine formula is an equation important in navigation, giving great-circle distances between two points on a sphere from their longitudes and latitudes 🌎 It is a special case of a more general formula in spherical trigonometry, the law of haversines, relating the sides and angles of spherical "triangles". Task: Implement a great-circle distance function, or use a library function, to show the great-circle distance between: Wagle Estate Rd, Padwal Nagar, Thane West, Thane, Maharashtra 400604, which is : N 19.189354, W 72.951225 Swami Vivekananda Rd, Thane West, Thane, Maharashtra 400602, which is : N 19.186333, W 72.966961 Distance: This uses the ‘haversine’ formula to calculate the great-circle distance between two points – that is, the shortest distance over the earth’s surface – giving an ‘as-the-crow-flies’ distance between the points (ignoring any hills they fly over, of course!). Haversine formula : a = sin²(Δφ/2) + co...