I took upon myself to try to do a OOP design for Waze, please give a feedback which is OOP design related. Also if you were the interviewer can you think of flow up questions?
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Collections.Generic;
using System.Drawing;
namespace JobInterviewTests
{
[TestClass]
public class WazeDesign
{
[TestMethod]
public void CarTest()
{
Car myCar = new Car();
UserMap mapByLocation = new UserMap(myCar.CurrentLocation);
mapByLocation.SetDestination(104410);
Assert.AreEqual(System.Drawing.Color.FromName("Purple"), mapByLocation.SuggestedRoute.RoadColor);
}
}
// different types, motorcycle, bus, private car....
public abstract class Vehicale
{
public int CurrentLocation { get; private set; }
public System.Drawing.Color RoadColor { get; set; }
public Vehicale()
{
GetLocation();
}
public void GetLocation()
{
CurrentLocation = Gps.Instance.GetLocation();
}
}
public class Car : Vehicale
{
public Car()
{
}
}
//should be a singletone, this is not a must.
//but looks reasonable
public class Gps
{
private static Gps _instance = null;
private Random random = null;
private Gps()
{
random = new Random();
}
public static Gps Instance
{
get
{
if (_instance == null)
{
_instance = new Gps();
}
return _instance;
}
}
public int GetLocation()
{
int result = -1;
try
{
result = random.Next(1000000);
}
catch (Exception ex)
{
throw new Exception("there was an error locating GPS info");
}
return result;
}
}
public class Road
{
//a road can contain all the cars you are passing by.
public List<Vehicale> Cars { get; private set; }
public System.Drawing.Color RoadColor { get; set; }
public Road()
{
Cars = new List<Vehicale>();
}
}
public class SuggestedRoute : Road
{
public SuggestedRoute()
{
RoadColor = System.Drawing.Color.FromName("Purple");
}
}
//the map contains all the roads nearby and the suggested Route
//Day and night colors
public class UserMap
{
public int CurrentLocation { get; set; }
public int Destination { get; set; }
public List<Road> Roads { get; set; }
public List<Vehicale> Vechicals { get; set; }
public SuggestedRoute SuggestedRoute { get; set; }
//first time you build the map you add all the car and roads near you
public UserMap(int currentLocation)
{
CurrentLocation = currentLocation;
Roads = DataServer.Instance.GetRoadsAroundLocation(CurrentLocation);
Vechicals = DataServer.Instance.GetVechicalesAroundLocation(CurrentLocation);
}
//you need to update the view, you do not need to rebuild everything
public void UpdateLocation(int currentLocation)
{
//update from GPS every 2 secs...
}
public void SetDestination(int destination)
{
Destination = destination;
SuggestedRoute = DataServer.Instance.GetSuggestedRoute(CurrentLocation, destination);
}
}
public class DataServer
{
private static DataServer _instance = null;
private DataServer() { }
public static DataServer Instance
{
get
{
if (_instance == null)
{
_instance = new DataServer();
}
return _instance;
}
}
public List<Road> GetRoadsAroundLocation(int currentLocation)
{
return new List<Road>();
}
public List<Vehicale> GetVechicalesAroundLocation(int currentLocation)
{
return new List<Vehicale>();
}
public SuggestedRoute GetSuggestedRoute(int currentLocation, int destination)
{
return new SuggestedRoute();
}
}
}