Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
606 views
in Technique[技术] by (71.8m points)

language agnostic - When to make class and function?

I am a beginner to programming when I start to code I just start writing and solve the problem. I write whole program in a single main function. I don't know when to make class, and functions.

What are good books which I read to learn these concepts?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

A very general question, so just a few rules of thumb:

  • code reuse: when you have the same or very similar piece of code in two places, it should be moved to a function

  • readibility: if a function spans more than a single page on screen, you may want to break it apart into several functions

  • focus: every class or function should do only one specific task. Everything that is not core to this purpose should be delegated to other classes/functions.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...