Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6351439
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T22:00:28+00:00 2026-05-24T22:00:28+00:00

I have the following interfaces defined: public interface IAudit { DateTime DateCreated { get;

  • 0

I have the following interfaces defined:

public interface IAudit {
    DateTime DateCreated { get; set; }
}

public interface IAuditable {
    IAudit Audit { get; set; }
}

The IAuditable interface says which classes I will have an Audit for. The IAudit interface is the actual Audit for that class. For example say I have the following implementations:

public class User : IAuditable {
    public string UserName { get; set; }
    public UserAudit Audit { get; set; }
}

public class UserAudit : IAudit {
    public string UserName { get; set; }
    public DateTime DateCreated { get; set; }

    public UserAdit(User user) {
        UserName = user.UserName;
    }
}

Now given an object which is IAuditable (User from above), I’d like to be able to create an intance of IAudit (UserAdit from above) by feeding in the IAuditable object into the constructor. Ideally i’d have something like:

if (myObject is IAuditable) {
    var audit = new IAudit(myObject) { DateCreated = DateTime.UtcNow }; // This would create a UserAudit using the above example
}

However I have a bunch of problems:

  • You can’t create an instance of an interface
  • No where in the code does it define which IAudit applies to which IAuditable
  • I can’t specify that the IAudit interface must have a constructor which takes an IAuditable

I’m sure this is a design pattern many have had before but I can’t get my head around it. I’d really appreciate if someone could show me how this can be achieved.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T22:00:30+00:00Added an answer on May 24, 2026 at 10:00 pm

    No where in the code does it define which IAudit applies to which
    IAuditable
    I can’t specify that the IAudit interface must have a
    constructor which takes an IAuditable

    You could fix these two by adding a CreateAudit() function to your IAuditable. Then you’d get an IAudit created from the IAuditable. As a bonus if you wanted to store a reference to the IAudit in the IAuditable (or vice-versa) so you can have them related to each other, it’s pretty easy to have an implementing class do that. You could also add GetAuditable() to IAudit to get the IAuditable it was created from, for example.

    Simple implementation would look like this (on a class implementing IAuditable):

    public IAudit CreateAudit()
    {
        UserAudit u = new UserAudit(UserName);
        return u;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have defined the following interface: public interface IHaveAProblem { string Issue { get;
Let's say I have 2 interfaces defined like so: public interface ISkuItem { public
I have two interfaces like these: public interface IMyInterface1 { string prop1 { get;
I have the following class & interface defined: public interface A { } public
I have the following interface which I'm trying to make COM-visible. When I try
I have the following classes public interface InterfaceBase { } public class ImplementA:InterfaceBase {
I have the following interface defined to expose a .NET class to COM: [InterfaceType(ComInterfaceType.InterfaceIsDual)]
I have the following base abstract class defined as: public abstract class BaseObject<T> :
my application has the following code: public interface IConfigurationManager { CustomSection Settings { get;
I'm developing an Android application. I have the following interface: public interface IDBAdapter {

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.