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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T21:53:10+00:00 2026-06-17T21:53:10+00:00

suppose we have a class structure where the code is divided in two parts

  • 0

suppose we have a class structure where the code is divided in two parts lets us say computer science and business, now this also further divides in terms of country also, say Indian (cs or MBA) and US (cs or MBA).
now let us consider a scenario where i created classes like

1)Education class(parent class)

2) MBA class extends Education class

3) BS (cs) class extends Education class

now in terms of country also i made the classes

4) INDIA_BS class extends BS (cs) class

5)INDIA_MBA class extends MBA class

6) US_BS class extends BS (cs) class

7) US_MBA class extends MBA class

now let us say i write code where the country is set in the classes-method which are lowest in hierarchy (i.e country classes INDIA_BS,INDIA_MBA,US_BS,US_MBA)
but the logic is similar.I pass country name and it is set.

so my questions are
1) is it wise to put the common logic in parent classes(if i do that way) and calling that method from the child class which is lowest in hierarchy).

2) if this is wrong than what are the principles of OOPS that it violate

3) does it violate SOLID principle also if yes then how ?

4) is it decreasing coherence of the child class if i am putting the common code in parent class.

please be elaborate as possible.
thanks

  • 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-17T21:53:11+00:00Added an answer on June 17, 2026 at 9:53 pm

    Your class diagram:

    Your class diagram

    i see x violations:

    1. Favor Composition Over Inheritance
    2. Program To An Interface, Not An Implementation
    3. Software Entities Should Be Open For Extension, Yet Closed For Modification
    4. etc

    So, i would suggest you use Abstract Factory pattern.
    Code:

        class Test
        {
            static void Main(string[] args)
            {
                IEducationFactory india = new IndianEducation();
                IEducationFactory newYork = new USEducation();
    
                IDiplom d1 = india.Create_BSC();
                IDiplom d2 = newYork.Create_MBA();
            }
        }
    
        public interface IDiplom
        {
        }
    
        public interface IEducationFactory
        {
            IDiplom Create_MBA();
            IDiplom Create_BSC();
        }
    
        public class IndianEducation : IEducationFactory
        {
            public IDiplom Create_MBA()
            {
                throw new NotImplementedException();
            }
    
            public IDiplom Create_BSC()
            {
                throw new NotImplementedException();
            }
        }
    
        public class USEducation : IEducationFactory
        {
            public IDiplom Create_MBA()
            {
                throw new NotImplementedException();
            }
    
            public IDiplom Create_BSC()
            {
                throw new NotImplementedException();
            }
        }
    

    And, your class diagram looks like:

    enter image description here

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

Sidebar

Related Questions

suppose we have this class structure: public class BaseClass { public BaseClass() { Console.WriteLine(Base
I have a data structure that represents C# code like this: class Namespace: string
Suppose I have this class: class MyClass(object): def uiFunc(self, MainWindow): self.attr1 = foo self.attr2
Suppose I have a huge list of elements with a structure like: <div class=item>
Suppose I have a class structure like the following, where I have a temporary
so here's the situation: suppose I have a class structure used to represent flexible
Suppose I have a structure (or a class that I use just for storing)
Suppose I have this structures in c++ : class A{ public: B b; }
Suppose I have class Foo(db.Model): bar = db.ReferenceProperty(Bar) foo = Foo.all().get() Is there a
Suppose I have: class Foo { ... }; class Bar : public Foo {

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.