How to write code with OOP mindset

When we talk about the OOP Design, it is all about how to write your code with OOP mindset.

This is very important if you are using OOP language as Java or C#.

Then how to build your OOP mindset when you started to write code.

1. Java Programming all started with Class and Object

No matter how small or big your program/app you will started with.

You have to think about Class and Object first.

Initialize the first object and next, started to cultivate the thinking that everything is an object

So try to avoid to write all your sample/prototype code into your main function. Think about more which elements are Object/Class, Method, Attribute. When you start to build the thought as this, you can see your coding reusability will be start to getting better and better. Make your componentalization concept maximized.

In the Java Programming real world, theoretically you will not use the Primitive Data Types compare to the Object Type.

For example,

If you have read through the clean code book, you know when your function have more than 3 parameters pass through there, it means something wrong there based on OOP Design.

If you have too much if-else code written there, it is wrong as well. It needs to use Object or redesign to refactor the code.

Why you are using utility class instead of design your object inheritance better

When to use Domain Driven Design better?

3. Writing function code

I will suggest that start to write what steps we need to complete it

Using comments instead to have your ideas ready

Started with OOP Objects.

Treat almost everything can be the objects.

4. OOP started with Drawing OO relationships

When you started to writing code, better to draw on paper on Class, Object,Relationship, Method and Attribute etc.

Later you can start to use some online class diagram tool, it helps to get into OOP Design as well.

5. Start to be always treat each line of your code with good Code Quality

Started with Naming Convention , then next Code readability.

You can refer to Google Coding Standard和 Oracle Java Coding Standard.

Also read through the clean code book as well.


要查看或添加评论,请登录

Caihua Liu的更多文章

  • Java ORM Framework

    Java ORM Framework

    In recent days, I have been discussing with my friends what is the best suitable ORM(Object Relational Mapping)…

    1 条评论
  • SQL VS NOSQL Database

    SQL VS NOSQL Database

    There are always different opinions and choices what you want to choose for you database in your applications…

  • Agile - XP VS Scrum

    Agile - XP VS Scrum

    Development team want to choose Agile Development Methodology from either SCRUM or XP(Extreme Programming) Let us talk…

  • How the Empire of Spring Framework Derived

    How the Empire of Spring Framework Derived

    In recent days, I spoke some of my friends about SpringBoot. We did talk about the Spring IOC(Inversion of…

  • Clean Code-Be a good programmer

    Clean Code-Be a good programmer

    This is a very recommended book called Clean Code: A Handbook of Agile Software Craftsmanship. It is a mandatory book…

  • JSON VS XML

    JSON VS XML

    There is another design question that always in the plate. Should we use json or xml as our data interchange pass…

  • JDK 8 is the past, Now we have JDK 17

    JDK 8 is the past, Now we have JDK 17

    This was the discussion between me and my friends on which is the best JDK version we should use at the moment. Today…

  • The Dynasty iteration of Javascript Frameworks

    The Dynasty iteration of Javascript Frameworks

    What is the most popular Javascript framework in the javascript market. I want go through the original first iteration…

  • Which version of Spring Framework version we should go with

    Which version of Spring Framework version we should go with

    In recent days, I have been discussing with my friends on what is the best Spring Framework should be on in order to…

  • When to use(Git CLI vs GitHub vs Git IDE Plugin)

    When to use(Git CLI vs GitHub vs Git IDE Plugin)

    Git has replaced the SVN and CVS to be the most popular source code version control system in the market from several…

社区洞察

其他会员也浏览了