1,105,399 Community Members

Class diagrams, is it OK to have no Inheritance?

Member Avatar
deucalion0
Junior Poster in Training
62 posts since Mar 2010
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Hey guys I have to create class diagrams for my software project and I was wondering what happens when there is no inheritance between my classes. I have five classes: Titlescreen, Program, Robot, Levels and Form1. None of these classes are abstract, they have no Inheritance between them, just Objects created between them.

The examples I have read through in books etc... all have inheritance as being the main poiunt for creating these diagrams, but I need to create them although my software seems simple in comparison to examples, such as shapes inheriting from the abstract shape class.

Can anyone shed some light on simple class diagrams? I have considered altering my software to have some inheritance for the purpose of creating better class diagrams, but that seems to against the whole point in inheritance.

Any help is appreciated.

Thanks!

Member Avatar
Knvn
Junior Poster in Training
86 posts since Feb 2011
Reputation Points: 14 [?]
Q&As Helped to Solve: 12 [?]
Skill Endorsements: 0 [?]
 
0
 

The class diagrams are used to identify how the objects are designed and how they are interacting with each other. Altering the code to create a diagram doesn't make any sense!

What is the problem, how you have find solution for that problem using oops(I mean how you have designed the classes)...without knowing these things its not possible for us to help you.

In order to design a class diagram, its not necessary that there should be an inheritance!

Member Avatar
Mitja Bonca
Posting Maven
2,561 posts since May 2009
Reputation Points: 557 [?]
Q&As Helped to Solve: 489 [?]
Skill Endorsements: 21 [?]
 
0
 

Its impossible to tell you what it should be. I or we (at least for those who dont know this example, and I dount anyone here does), doubt its possible to predict how the inheritance shoud be in yout particular exampe.

There is much to learn on this area of OOP. Actualy, this is the whole point of it.

Inheritance: you stated it. Example:

class Program
    {
        static void Main(string[] args)
        {
            DerivedClass class1 = new DerivedClass();
            BaseClass class2 = (BaseClass)class1;
            
            //
            //1. simple class calls:
            //
            class1.DoWorkB(); //calls new method
            class1.DoWorkA(); //calls old method            
            class2.DoWorkA();

            //
            //2. virtual - override methods:
            //both will call the both methods (in base and derived classes):
            //
            class2.Base_OverridenMethod();
            class1.Base_OverridenMethod();

            BaseClass _bClass = new BaseClass();
            _bClass.Base_OverridenMethod(); //this will call onle base virual method!

            //
            //3. abstract - override:
            //
            NewClass2 nc = new NewClass2();
            nc.SomeMethod();
            Console.WriteLine("{0}", nc.GetX);
            Console.ReadLine();
        }
    }

    class BaseClass
    {
        public void DoWorkA()
        {
            Console.WriteLine("Method of classs A");
        }

        public virtual void Base_OverridenMethod()
        {
            Console.WriteLine("Base method");
        }
    }

    class DerivedClass : BaseClass
    {
        public void DoWorkB()
        {
            Console.WriteLine("Method of classs B");
        }

        public override void Base_OverridenMethod()
        {
            base.Base_OverridenMethod();
            Console.WriteLine("Overriden method of Base method");
        }
    }

    abstract class NewClass
    {
        protected int x = 2;
        public abstract int GetX { get; }

        public abstract void SomeMethod();        
    }

    class NewClass2 : NewClass
    {
        public override int GetX
        {
            get { return x + 2; }
        }

        public override void SomeMethod()
        {
            Console.WriteLine("New value is:");
        }
    }

I did some simple examples of using Inheritance, and class (methods and properties) modifyers.

Member Avatar
deucalion0
Junior Poster in Training
62 posts since Mar 2010
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Thanks for the help and the examples! I know it is a lot to ask, I know it is difficult to say for sure how it should be done, I was curious about class diagrams and the fact that I have no inheritance. Here are the four classes that make up my program, I am trying to figure out how to connect them together using a diagram:

Classes

I am aiming to draw something like thsi:
Diagram

Thanks again for your help, and Mitja that is an excellent explanation on Inheritance!

You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article