Question

I'm a self taught C++ programmer, given that my first programming language was Fortran (many years before touching C++) I write Structured C++.

Now I want to take next step and learn Object Oriented Programming.

I wrote small app for parsing log files, I would prefer to write the same app in OOP approach instead of making something completely new. Think side benefit would be real comparison of two approaches.

Question is - should I start from scratch or can I gradually rewrite Structured code? If rewriting is a go, What would be the best approach to do that?

I have to admit that I am a bit confused with OOP.

Was it helpful?

Solution

It actually is completely and totally up to you whether you want to start from scratch or attempt to rewrite. Both have their advantages and disadvantages.

Once you understand the basics of OOP, it is incredibly easy to implement and I have found that I prefer OOP over Structured.

Here's an example of a simple structured program converted to OOP: Structured:

Class Foo
{
     public static DoSomething()
     {
         return true;
     }
}

To implement this we would say:

main()
{
    Foo f;
    f = Foo.DoSomething();
}

Now we will take the exact same code and make it OOP:

Class Foo
{
    public Foo() // Constructor for object
    {
    }
    public DoSomething()
    {
        return true;
    }
}

And to implement:

Foo f = new Foo()
f.DoSomething()

Once you understand OOP, there is a vast amount of languages you can learn that are based heavily on object (e.g. Python). So it's good that you are trying to learn and I bid you best of luck!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top