OOP concept in c#

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • weird0

    #1

    OOP concept in c#

    C# corner on one of its tutorial says "Polymorphi sm allows objects to
    be represented in multiple forms".

    Can somebody elaborate and make it with an example.

    How can an object be represented in multiple forms when c# does not
    allow multiple inheritance?

    Regards
  • Mr. Arnold

    #2
    Re: OOP concept in c#


    "weird0" <amirediwan@gma il.comwrote in message
    news:a0b7451f-d9ac-45a1-846f-c68338154c43@o6 g2000hsd.google groups.com...
    C# corner on one of its tutorial says "Polymorphi sm allows objects to
    be represented in multiple forms".
    >
    Can somebody elaborate and make it with an example.
    >
    How can an object be represented in multiple forms when c# does not
    allow multiple inheritance?
    >
    Maybe, you're mis-interpreting.

    MODEL-VIEW-PRESENTER



    click 'Shows'

    click 'Design Patterns Bootcamp: Model View * Patterns'

    view part 1-5

    Comment

    • Jeff Louie

      #3
      Re: OOP concept in c#

      This may help.

      Latest news coverage, email, free stock quotes, live scores and video are just the beginning. Discover more every day at Yahoo!


      IMHO, C# does allow a very limited form of multiple inheritance through
      "interfaces " which are similar to pure virtual classes in C++. If you
      accept that interfaces in C# are analogous to pure virtual classes in
      C++ then, in essence, C# supports single inheritance of an
      implementation hierarchy and multiple inheritance of interfaces.

      Regards,
      Jeff

      *** Sent via Developersdex http://www.developersdex.com ***

      Comment

      • =?ISO-8859-1?Q?Arne_Vajh=F8j?=

        #4
        Re: OOP concept in c#

        weird0 wrote:
        C# corner on one of its tutorial says "Polymorphi sm allows objects to
        be represented in multiple forms".
        >
        Can somebody elaborate and make it with an example.
        >
        How can an object be represented in multiple forms when c# does not
        allow multiple inheritance?
        You are looking at two different things.

        multiple parents : one child class with multiple parent classes

        polymorphism : one parent class with multiple child classes that
        can all be treated the same

        Arne

        Comment

        • .\\\\axxx

          #5
          Re: OOP concept in c#

          On Dec 3, 2:52 am, weird0 <amiredi...@gma il.comwrote:
          C# corner on one of its tutorial says "Polymorphi sm allows objects to
          be represented in multiple forms".
          >
          Can somebody elaborate and make it with an example.
          >
          How can an object be represented in multiple forms when c# does not
          allow multiple inheritance?
          >
          Regards
          At the risk of over simplifying:

          If Shape is a class.
          Square, Triangle, etc. inherit from Shape and override the Draw()
          method.
          your program can say

          Shape x = new Square();
          x.Draw();

          So your x object is a Shape instantiated as a Square - and is
          therefore represented in multiple forms (two, in this case).

          If your oubjects also implement interfaces, each implemented interface
          gives another potential reference - so you could have

          (ITwoDimentsion alObject) x.Color = Red;

          where x is now referred to as an ITwoDimentsiona lObject.

          Every objcet in .Net inherits frob Object - and so can always be
          referred to as its own type and Object, at the very least. So every
          object is polymorphic.


          Comment

          • weird0

            #6
            Re: OOP concept in c#

            No... actually , what i want is that I have one user-defined class say
            Animal.

            Now, I want its single object representation through a label or
            whatever, in every form. What should be design of classes?

            If I update the attributes inside the object, how will it be updated
            and changes be reflected in the all the three forms, say i have made
            the change in Form3.

            Regards

            Comment

            • Marc Gravell

              #7
              Re: OOP concept in c#

              If the class supports change-notification, then any of the
              observer-based patterns / MVP should allow it to be updated in all
              bound user-interface elements. So you should be able to just use
              normal data-binding. You might need to watch for threading, but that's
              about it.

              Change notification can commonly be either as a set of events
              ({PropertyName} Changed for every {PropertyName}) , or via
              INotifyProperty Changed.

              Marc


              Comment

              • Jeff Louie

                #8
                Re: OOP concept in c#

                weird0... There are many ways to do this and the answers are not that
                simple. On the most simple level look at the Observable pattern that
                Mark suggest. Typically, the object of class Animal provides an Event
                that can notify listeners of changes in the object's state and listeners
                can register an interest in that Event. This works for a single View,
                but gets complicated when there are multiple Views bound to the same
                data.

                You may be interested in the Passive View pattern where the Controller
                may own the Model and View. The Controller may update the Views using
                Events. In this pattern, there is no direct coupling between the Model
                and the Views. The Controller talks directly to the Model and may fire
                Events to the Views. The Views talk directly to the Controller. This
                pattern works both locally and remotely.

                You can google on:
                Observable
                Model View Controller
                Model View Presenter
                Passive View
                Supervising Controller

                Regards,
                Jeff

                *** Sent via Developersdex http://www.developersdex.com ***

                Comment

                • Jon Skeet [C# MVP]

                  #9
                  Re: OOP concept in c#

                  Liz <liz@tiredofspa m.comwrote:
                  create a method in Animal which can notify any class of changes in its
                  state; Color=Blue, etc
                  >
                  create a public method in Animal and a collection which will other classes
                  can call to "register" their "interest" in such state changes
                  There's no need to write your own type of collection here - this is
                  precisely what events are good at. The subscriber provides a delegate
                  which is called when the appropriate "interestin g thing" occurs.

                  --
                  Jon Skeet - <skeet@pobox.co m>
                  http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
                  World class .NET training in the UK: http://iterativetraining.co.uk

                  Comment

                  Working...