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

  • Home
  • SEARCH
  • 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 503613
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T06:24:43+00:00 2026-05-13T06:24:43+00:00

If there are 3 interfaces like the following public interface IWeapon { void Kill();

  • 0

If there are 3 interfaces like the following

public interface IWeapon {
void Kill();
}

public interface ISword:IWeapon {
void Slice();
}

public interface IShuriken: IWeapon {
void Pierce();
}

public class Ninja {
public IWeapon Weapon {get;set;}
public void BrutalKill() {

/* warrior must pierce, pierce, pierce and then kill 


*/

}
public void HonorKill {
/* warrior must kill by one slice */
}
}

For a scenario like this how would you wireup the container and what would your method body look like for BrutalKill and HonorKill ?

EDIT: Based on comments, I was thinking on the lines a ninja should be armed with a weapon… if it wants to be armed with a sword or shuriken…should be decided later… not sure if i am thinking right .. maybe we need to subclass Ninja as NinjaWithShuriken and NinjaWithSword

  • 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-13T06:24:43+00:00Added an answer on May 13, 2026 at 6:24 am

    Not sure if this is what you are looking for, but I would have this:

    // first some implementations
    public class Sword : ISword {
        public void Kill() { // imp }
        public void Slice() { // imp }
    }
    
    public class Shuriken : IShuriken {
        public void Kill() { // imp }
        public void Pierce() { // imp }
    }
    
    // and I would change the Ninja class to
    public class Ninja {
        public ISword Sword { get; private set; }
        public IShuriken Shuriken { get; private set; }
    
        public Ninja(ISword sword, IShuriken shuriken) {
            this.Sword = sword;
            this.Shuriken = shuriken;
        }
    
        public void BrutalKill() {
            Shuriken.Pierce();
            Shuriken.Pierce();
            Shuriken.Pierce();
    
            // either weapon can kill
            // so lets close the distance and use the sword
            Sword.Kill();
        }
    
        public void HonorKill {
            Sword.Slice();
        }
    }
    
    // creating the class
    // where Ioc.Resolve is specific to the container implementation
    var ninja = new Ninja(IoC.Resolve<ISword>(), IoC.Resolve<IShuriken>());
    

    Update
    I like Phil Sandler’s comment so a quick update to reflect that:

    // a ninja interface
    public interface INinja {
        void BrutalKill();
        void HonorKill();
    }
    
    // and then update the ninja class to
    public Ninja : INinja {
        ...
    }
    
    // and have the ninja class created like this with the container
    // resolving the dependencies:
    var ninja = IoC.Resolve<INinja>();
    

    Update
    Based on the update to the original question I would say:

    public interface IWeapon {
        void Attack();
        void Kill();
    }
    
    public class Sword : ISword {
        public void Attack() {
            // implement as a slash
        }
        ...
    }
    
    public class Shuriken : IShuriken {
        public void Attack() {
            // implement as a pierce
        }
        ...
    }
    

    The idea being that we don’t really care how Sword and Shuriken implement Attack, as long as the ninja can use them to perform his duty when called upon. The assassination can be caried out how the specific ninject wishes, as long as the job gets done within the confines of the stated agreement, in this case by Attacking.

    // create the specific ninja
    var swordNinja = new Ninja(IoC.Resolve<ISword>());
    var shurikenNinja = new Ninja(IoC.Resolve<IShuriken>());
    
    // with the ninja class updated to only have an IWeapon 
    // property that gets set in the constructor.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 255k
  • Answers 255k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I just tried this with an app on 1.5 and… May 13, 2026 at 10:20 am
  • Editorial Team
    Editorial Team added an answer Has you can see at this page, Enable = False… May 13, 2026 at 10:20 am
  • Editorial Team
    Editorial Team added an answer Are you making the same page for both devices? Usual… May 13, 2026 at 10:20 am

Related Questions

I seem to have faced this problem many times and I wanted to ask
I'm trying to brush up on my design pattern skills, and I'm curious what
I've been coming up with a lot of dead ends on this question. Supposedly,
When I try to compile an assembly in VS 2008, I got (occasionally, usually
The following test case fails in rhino mocks: [TestFixture] public class EnumeratorTest { [Test]

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.