0

Based on this question I think while the aim of OOP is not necessarily to copy real world objects, they could be source of inspiration to design a software or solve a problem or even learn the OOP itself.

For example for an application which deals with drawing, a Bitmap could be regarded like a Page, then as a page has back color, we can define a BackColor attribute for it. But we may realize a real page has not text color and it's the attribute of the pen, so we can define a class named Pen which is used for drawing and has a Color, LineWeight or ..

I always look for such analogy and inspirations of objects and their interactions when I develop a software, but I don't have a systematic or clear definition for what I am doing. I don't know which aspects of OOP I am copying.

Is it an acceptable technique in OOP? Do you use it? Is it possible that I violate an OOP guideline while I am using this technique?

I would like to know how this technique may help me to follow OO principles, so I can consciously use it.

closed as primarily opinion-based by Doval, user40980, gnat, Telastyn, user22815 Feb 19 '15 at 15:23

Many good questions generate some degree of opinion based on expert experience, but answers to this question will tend to be almost entirely based on opinions, rather than facts, references, or specific expertise. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 4
    You're not going to find a systematic way to produce good code. I'd also be more concerned with learning what makes good code good than dogmatic adherence to some paradigm or another. OOP is a means, not an end. – Doval Feb 19 '15 at 14:53
  • 2
    I voted to close this question because it's an interesting discussion topic, but a bad question. – Telastyn Feb 19 '15 at 15:25
  • 3
    It is pretty clear, but it does not fit the Q&A format well. There are many possible, lengthy, opinion-based answers. Good questions for the site should have one, 2-5 paragraph answer based on fact or expert consensus. And given your history of turning these sort of questions into discussions makes me less inclined to let such discussion inclined questions remain. – Telastyn Feb 19 '15 at 15:34
  • 2
    Hints are not answers. – Telastyn Feb 19 '15 at 15:42
  • 1
    Given the number of views, answers and votes, that question is wildly more inspiring. It also has some close votes currently. I personally didn't vote for it because I was curious about other's perspectives. I don't vote for it now because there are a boatload of people that like it. I am not curious about the answers to this question, since I've a good idea how it will play out - a whole lot of arguing over "what is OO" and "what is proper OO" without much insight. The exact sort of thing that "primarily opinion-based" exists to combat. – Telastyn Feb 19 '15 at 19:54
1

You're conflating multiple things when you over analyse the problem.

For example, when designing a page object that reflects a real-world sheet of paper you start to consider pens. Don't!

Take just the sheet of paper and consider its properties. It has a paper colour, texture, size. Then do not try to map your preconceptions of computing terms to the object. A sheet of paper does not have a 'backcolour'. It has a colour, of the dye or material used in the manufacture of the paper. This is different to any concept of drawing using a pen that has 2 inks (assuming a very unusual pen that draws both a wide underlay and a ink nib).

Its important to try not to 'map' your concepts to the item. and simply look at the entity as an independant thing. consider what only it does, not what can be done to it or any other item. Then you'll find the properties fall into place, and you can move onto the next item, eg a pen and what properties it has.

When considering the object, also forget the methods you'll use to modify it. Start with the properties only. Methods are added as ways to interact and modify those properties so they are not really important in the design stage. eg. your paper can hold writing on it, so its property is that it can maintain text blocks in particular positions. You'll add a method to add new writing to it but when designing its the writing held by the paper that is much more important than how that writing gets written.

Hopefully this'll help clear your thoughts, design can be a bit vague and loose at the best of times!

  • You said about TextBlocks it was again a useful concept may taken from a real page. And the text color should be associated with the block than the page. I just think there are many things to learn and get inspired, I just don't know why this question wasn't well receipt. Do you have other techniques for modeling? Don't you get inspired by real objects?! is it odd? – Ahmad Feb 19 '15 at 15:24
  • I know "analysis paralysis" is a real thing, but sometimes you can get a lot of insight from real world objects. – gbjbaanb Feb 19 '15 at 15:26

Not the answer you're looking for? Browse other questions tagged or ask your own question.