5 Replies - 901 Views - Last Post: 22 June 2017 - 10:59 PM

#1 garbus  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 22
  • Joined: 18-June 17

I can't understand the OOP Design Process

Posted 20 June 2017 - 08:23 PM

Whenever I was required to build a project, I always managed to build it, not beforehand devising a plan or design, but after first writing a class that was needed, fleshed out the entire project, building from the bottom-up. Now I know this is not the proper way to create software, but it is not easy for me to wrap my head around what is called Objected Oriented Analysis and Design. I can more easily understand top-down procedural design, for it consists in merely breaking down tasks into sub-tasks, things which have their counterpart in code, functions. But Object Oriented Analysis and Design I cannot easily understand, for I do not understand how one can know what classes are needed and how they will interact, unless they know how they will be coded.

For once we introduce the concept of classes and objects into the design process, we can no longer design top-down, because we are no longer breaking down our problems into those things which can be implemented as procedures. Instead, according to what I have read on the subject, we must determine what classes are needed, and create various artifacts in Unified Modelling Language, which we can then use when we implement the software. But this kind of design process I do not understand. For how does one know which classes they will need, and how they will interact, unless they have already conceived of the whole system?

This then is my problem. I do not understand how to design an Object-Oriented System, although I do understand the concepts of Object Oriented Programming, and can use those concepts in any Object Oriented Programming language that I know. Therefore I need someone to explain to me what simple process I can use to design Objected Oriented Systems in a way that makes sense to me.

Is This A Good Question/Topic? 0
  • +

Replies To: I can't understand the OOP Design Process

#2 jon.kiparsky  Icon User is offline

  • Chinga la migra
  • member icon


Reputation: 10688
  • View blog
  • Posts: 18,305
  • Joined: 19-March 11

Re: I can't understand the OOP Design Process

Posted 20 June 2017 - 09:07 PM

Quote

For once we introduce the concept of classes and objects into the design process, we can no longer design top-down,


I think of this differently. To me, object-oriented design takes a higher-level design stance, and so is even more "top-down" than the process you describe. What I mean is that in object-oriented design you can think of your top-level requirements not just as functions, but as overall class behavior. You're not just writing a handful of functions, you're specifying and implementing an API.

Quote

because we are no longer breaking down our problems into those things which can be implemented as procedures.


Again, I take a different view. We are still breaking down our problems into procedures. The difference is that now we're restricting the data manipulations to the places where they most naturally belong. Each class "tends to its own knitting", which makes it easier for everyone, assuming that you obey reasonable practices about encapsulation, ie the Law of Demeter. It's easier to write the class (you need less defensive coding) and it's easier to interact with the class (since you don't have to write low-level code in that object's domain, you just send it a high-level signal on the API that it defines and hopefully documents). It's easier to debug the whole program, since problems divide naturally into bad responses to good calls and good responses to bad calls, and in either case it's easy to understand where you should start looking.

However, it's still critical to follow good clean code practice, which means any procedure you define should be short and do exactly one thing, which implies a top-down evolution of your procedure from broad requirement down to the details of implementation.
Was This Post Helpful? 4
  • +
  • -

#3 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 13493
  • View blog
  • Posts: 53,897
  • Joined: 12-June 08

Re: I can't understand the OOP Design Process

Posted 20 June 2017 - 09:09 PM

Not sure if anyone can explain it in away that makes sense to you... have you read up on the wikis and what not about the topic? The concept of thinking about what you need, how folks will interact, data requirements, actions, etc.. and start fleshing out the object from that.
Was This Post Helpful? 0
  • +
  • -

#4 tlhIn`toq  Icon User is offline

  • Xamarin Cert. Dev.
  • member icon

Reputation: 6507
  • View blog
  • Posts: 14,374
  • Joined: 02-June 10

Re: I can't understand the OOP Design Process

Posted 21 June 2017 - 03:08 AM

Let me know if this tutorial on OOP helps.
http://www.dreaminco...lasses-objects/

Quote

For how does one know which classes they will need, and how they will interact, unless they have already conceived of the whole system?

You're not wrong. But why is that a problem? When you get the assignment/story/contract/proposal that should be the concept of the whole system. Not a design for every little subroutine, but the 30,000ft overview. Then you just start breaking it down.

Then again, OOP is modular and 'black box'. Even if you only know 1/4 of the entire program you still know the entire system that you're responsible for. You really only need to know 3 things: The parameter coming in, the result going out, and what you're supposed to do to get from one to the other. What happens inside that box is up to you. If you take in 6 strings, and output one CustomerRecord then you've done your job and the rest of the program doesn't need to know if that was done with a big loop, a REST call, or creole voodoo. Its just like a car. Do you think the transmission knows or cares how the engine works? It doesn't know if its a gasoline or diesel. It takes in rotary motion, and outputs rotary motion at a different speed and torque. The axles take that (again not knowing or caring how it was made) and shifts it 90 degrees to the wheels.

Quote

Instead, according to what I have read on the subject, we must determine what classes are needed, and create various artifacts in Unified Modelling Language, which we can then use when we implement the software.

Yeah sure... If you're still in school. But that's part of the learning curve. I tend to grab a white board and start blocking out the major chunks, make some notes about datatypes and "don't forget xyz" - Which I suppose is just lazy/sloppy UML after doing this for so long. All I'm saying is there is no "one right way".

Personally I see OOP as a cyber reflection of the physical world. Most programs exist as a way to accomplish something that mimicks or interacts with the real world. If its a program for interacting with your home weather station then you already know the objects: The station, its interface, and the results which are weather objects: temperature, wind, air pressure and so on. You don't have to invent anything. Just define in code what already exists in the world. If you're making a program to control a machine on a factory floor its the same thing. The machine already exists. It has objects like a safety interlock, hydrolic ram, limit switches, stepper motor... Code classes for each of these. The machine itself is your guide.
Was This Post Helpful? 4
  • +
  • -

#5 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 5898
  • View blog
  • Posts: 20,137
  • Joined: 05-May 12

Re: I can't understand the OOP Design Process

Posted 21 June 2017 - 11:51 AM

Having come from a procedural programming background, I too struggled with that initial leap into designing the object oriented way. I forget which book helped me with the breakthrough, but it comes down to "message passing" and the Law of Demeter as noted by jon.kiparsky. At the time, I didn't know that was the names for the concepts, but it was the application of those concepts that gave me the A-ha! moment.
Was This Post Helpful? 1
  • +
  • -

#6 ndc85430  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 592
  • View blog
  • Posts: 2,490
  • Joined: 13-June 14

Re: I can't understand the OOP Design Process

Posted 22 June 2017 - 10:59 PM

One does not need to know about all the classes that will be needed ahead of time - it's possible to let the design emerge as we go. Test-driven development is an approach that facilitates this - we start by writing a test for functionality that we want to build and in doing so, are forced to think about the way we want to use our classes in terms of the API that we want, as jon.kiparsky alluded to above (i.e. we're thinking about the "what" we want to do before the "how" it is done). Working this way will also help us to discover what other classes we need to support what we're working on right now.

There are two approaches to TDD: "inside out" and "outside in". See, e.g. this for a discussion. The former is easier to begin with and a good book on the subject is Beck's "Test-Driven Development: By Example" (Addison-Wesley).
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1