I hope I can explain this a bit decently, as today it blows up a fuse in my brain. I am learning TDD in C #, so I'm still trying to remake my brain to fit it.
Say I have a User class that previously had a static method for retrieving a User object (simplified below).
public static User GetUser(string username)
{
User user = GetUserFromCache(username);
if(user == null)
{
user = GetUserFromDatabase(username);
StoreObjectInCache(user);
}
return user;
}
So I'm trying to rewrite this to use dependency injection so that I can fake the GetUserFromDatabase method if it should go there. This means that I have to make the function non-static. While the data access layer would create a user object from the database, matching returned columns with object properties, retrieving from the cache would return a real blue User object . However, in the non-stationary method, I canβt just say
this = GetUserFromCache(username);
Because it just doesn't work. Although I am by no means a global expert on how to dance around this with OO, it seems I almost needed to grab the User object from the cache and write another mapping function that would save the returned properties of the user object in a new User instance.
? OO, ? , , ? - ?