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 8349973
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T08:10:20+00:00 2026-06-09T08:10:20+00:00

My first interface-based time of programming and some confusions in how to design the

  • 0

My first interface-based time of programming and some confusions in how to design the interfaces.

I have created an interface for Relationships between two nodes, like this:

public interface IOWLRelation
{
    IOWLRelation AddSubClass(IOWLClass parent, IOWLClass child);
}

Then I created the class to implement this interface, like this:

class OWLRelation: IOWLRelation
{
    public OWLClass Parent { get; set; }
    public OWLClass Child { get; set; }

    public IOWLRelation AddSubClass(IOWLClass parent, IOWLClass child)
    {
        this.Parent = (OWLClass) parent;
        this.Child = (OWLClass) child;
        return this;
    }

}

well first of all: do you see a bad-practice in the way I declared these class and interface?
Now my confusion is about those two public properties I have defined in my class: Do I need to also define them in the Interface?
Also what if I want to add a enumeration member to this class?
Whatever I add to my class I should also add it to its interface?

More importantly in the method implementation, I am passing Interface to the parameers of that method, is it bad or correct? should I pass interface or should I pass their real class?

  • 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-06-09T08:10:22+00:00Added an answer on June 9, 2026 at 8:10 am

    In this case, I would do your implementation a little bit differently. If you think through the workflow of someone using your interface, it is a little confusing. You have to create a OWLRelation object first, then call the AddSubClass method, which just returns the object you already created. I would use a factory method instead:

    public interface IOwlRelation
    {
        OwlClass Parent { get; }
        OwlClass Child { get; }
    }
    
    public class OwlRelation : IOwlRelation
    {
        public OwlClass Parent { get; private set; }
        public OwlClass Child { get; private set; }
    
        public static IOwlRelation Create(OwlClass parent, OwlClass child)
        {
            return new OwlRelation
            {
                Parent = parent,
                Child = child
            };
        }
    }
    

    Notice the Create method is static, so you don’t have to create an instance of it just to get an instance of it. Also, the Parent and Child classes are read-only through the interface, but you can set them from inside the class. This is generally a good practice to keep the properties from being overwritten later, but you don’t necessarily have to do it that way. I also renamed the classes to use normal camel casing, even for acronyms, since that’s part of the C# naming standard.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've just created my first view-based NSTableView in Interface Builder and I've correctly set
I have navigation-based application with first RootViewController. I wanna to protect it with password
I'm trying to design an interface for a web-based application that allows the user
First off, my code: @interface Block : NSObject { NSData *data; NSInteger slice_count; }
My first question =). I'm writing a video game with a user interface written
I realized that appears this interface in .NET Framework 4.5 I was looking first
I'm building a game of which the interface is one of the first items
Below is my code: First Category.h #import <Foundation/Foundation.h> @interface Category : NSObject { NSMutableArray
I would like to emulate the following interface: interface MultiSideEffectFunction<T> { void action(T first,
first take a look on this picture from localScope app : i have 2

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.