Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Recommendations for how to do OOP design [closed]

I find that whenever I begin writing an app in Java/C#, things start off good, but over time, as the app becomes more complex, it just gets more and more complicated. I've become aware of the fact that I'm not very good at design and high level architecture. All my classes become fairly strongly coupled and the design isn't "elegant" at all. I'm fairly competent at "low level" programming. That is, I can get just about anything done within a function or a class, but my high level design is weak and I'd really like to improve it. Does anyone have pointers to techniques, books, etc. that would be helpful in making me a better software engineer?

like image 452
Chris Avatar asked Oct 29 '08 17:10

Chris


People also ask

How does obeying the open-closed principle improve the design of our code?

The Open Closed Principle is a design principle that states that software components (such as classes and methods) should be open for extension but closed for modification. In other words, it means that you can add new functionality to your software without having to change the existing code.

What is are the most important concepts in OOP that help with design?

Now, there are four fundamental concepts of Object-oriented programming – Inheritance, Encapsulation, Polymorphism, and Data abstraction. It is very important to know about all of these in order to understand OOPs.

What object-oriented concepts are needed to implement the open-closed principle?

In object-oriented programming, the open–closed principle states "software entities (classes, modules, functions, etc.) should be open for extension, but closed for modification"; that is, such an entity can allow its behaviour to be extended without modifying its source code.


3 Answers

I disagree about starting with a book on design patterns or refactoring.

In my opinion, for a solid OO design, you should first be familiar with the main OO design principles, then understand how your problem can be represented in those basic principles. Then you can start discovering opportunities for applying design patterns and refactoring techniques in order to achieve those fundamental principles.

I would start with this book:

Agile Software Development, Principles, Patterns, and Practices by Robert C. Martin

In this book, Robert Martin describes the fundamental principles that make a good OO design, all of them related to encapsulation, coupling and modularity:

  • The Open/Closed Principle
  • Liskov Substitution
  • Dependency Inversion
  • Granularity
  • Common Closure
  • Reuse
  • No Cyclic Dependency
  • Stability Of Dependency
  • Abstraction And Stability

After all, almost every Design Pattern and Refactoring technique I have seen documented in GoF and Fowler is aimed at achieving one of several of these basic principles, depending on their relative priority for a given scenario.

like image 150
Sergio Acosta Avatar answered Oct 04 '22 03:10

Sergio Acosta


Books:

  • Code Complete, by Steve McConnel
  • Design Patterns, by Gamma, et. al.
like image 35
jakber Avatar answered Oct 04 '22 01:10

jakber


I would start by sketching my design. That sketch could be a box and arrow diagram to show relationships between classes or it could be a variation on UML (or perhaps even standard UML). But I find that sketches help me see that a design is good/bad and maybe even how to fix it.

I would also look at a book on design patterns.

like image 41
Thomas Owens Avatar answered Oct 04 '22 02:10

Thomas Owens