© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
31 replies
stigzler

❔ Help with Dependency Inversion Principle

Hi - could anyone help me with understanding the dependency inversion principle, please? Done lots of reading, but I just cant get it. Some quickly constructed code below as an example. How would I use DIP in this scenario?
    public interface ICacheManager
    {
        Directory CacheRootDirectory { get; set; }
        Image NoImageFileImage { get; set; } 
        Image CorruptImageFileImage { get; set; }

        void CacheImage(Image image, string path, string filename, Size? resizeTo = null);

        void RetrieveImage(string path, string filename);

        void ClearCacheFolder(string path);     
    }
    
    public class CacheManager
    {
        public Image RetrieveImage(string path, string filename)
        {
            Image cachedImage
            // Stuff here
            
            return cachedImage
        }
    }
    
    public class GamesListViewer
    {    
    
        CacheManager cacheManager;
    
        public void PopulateCacheImages()
        {
            for each (ListItem item in GamesList.Items)
            {
                item.Image = cacheManager.RetrieveImage("\Boxart\Front", item.filename);
            }
        }
        
    
    }
    public interface ICacheManager
    {
        Directory CacheRootDirectory { get; set; }
        Image NoImageFileImage { get; set; } 
        Image CorruptImageFileImage { get; set; }

        void CacheImage(Image image, string path, string filename, Size? resizeTo = null);

        void RetrieveImage(string path, string filename);

        void ClearCacheFolder(string path);     
    }
    
    public class CacheManager
    {
        public Image RetrieveImage(string path, string filename)
        {
            Image cachedImage
            // Stuff here
            
            return cachedImage
        }
    }
    
    public class GamesListViewer
    {    
    
        CacheManager cacheManager;
    
        public void PopulateCacheImages()
        {
            for each (ListItem item in GamesList.Items)
            {
                item.Image = cacheManager.RetrieveImage("\Boxart\Front", item.filename);
            }
        }
        
    
    }
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

✅ Dependency Inversion Principle, Dependency Injection
C#CC# / help
3y ago
Dependency Inversion
C#CC# / help
2y ago
❔ Can someone help me understand this statement around dependency inversion with an example?
C#CC# / help
3y ago
Open Closed Principle confusion
C#CC# / help
2y ago