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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T16:23:30+00:00 2026-05-22T16:23:30+00:00

MyObject has a shape and the shape have to be chosen and passed as

  • 0

MyObject has a shape and the shape have to be chosen and passed as argument to the ctor, can’t exist a MyObject whitout a shape and the shape can’t vary along his life. It happens often in real life.

namespace JackNova.ConsoleClient.Test.Fun
{
abstract class Shape { }

class Circle : Shape { }
class Square : Shape { }
class Triangle : Shape { }

static class Shapes
{
    public static Circle Circle { get { return new Circle(); } }
    public static Square Square { get { return new Square(); } }
    public static Triangle Triangle { get { return new Triangle(); } }
}

class MyObject
{
    public Shape Shape { get; private set; }

    public MyObject(Shape shape)
    {
        this.Shape = shape;
    }

}

class Test
{
    static void Run()
    {
        MyObject coolOne = new MyObject(Shapes.Circle);
    }
}
}

I think I’m violating some principle here, the open closed one for example.
My purpose is to simplify developing at design time. As you can see when I instanciate MyObject I don’t have to remeber wich kind of objects I can pass as argument but they are instanciated and passed by the abstract class.

Do you think this sucks?

  • 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-22T16:23:31+00:00Added an answer on May 22, 2026 at 4:23 pm

    It’s fine to have an abstract class and a class which takes a reference to an instance of that abstract class in the constructor and sets an effectively-readonly property.

    I would question your use of properties in the static class though:

    • How do you benefit in usage over just calling new Circle()?
    • If there were a benefit, I think it would still make sense to make these methods instead of properties.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have come across a class that has an immutable property: MyObject[] allObjs The
Simple Silverlight question: I have an ObservableCollection<MyObject> in my viewmodel. Every MyObject has a
I have an instance of an object myObject that has a few UIImage objects
I have a collection of objects as Dim XXX As IEnumerable(Of MyObject) which has
My project has some MyObject and the MyObject have a property of List<MyObject> .
I have myObjects = List(of myObject) myObject has Public Property myProperty as string Is
Have a List bound as the itemssource for a grid. MyObject has properties that
I have an application that has an array of pointers to MyObject objects: MyObject
I have a problem with unit tests in Android. My object MyObject has a
I have a List<MyObject> ... MyObject has a propert called LineId (integer)... So, I

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.