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!

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!

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.

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!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.