c# - using a class or a function -


sorry noob question i've had hard time distinguishing situations when it's create function or class. of smaller programs write @ work, write whole bunch of functions carry out specific tasks. programs work intended. however, when have of more senior developers take give me critique, rewrite lot of functions on class. these coworkers don't want incompetent (i started job junior developer) asking them why did that. guys think?

that broad question , have understand concept of object oriented programming , when should use it.

note: bellow find personal opinions (some of them borrowed great books' authors , experienced programmers), , sure things highlighted bellow, not reflect entire power of object oriented thinking , design. these gained throughout experience , feedback.

0. use case of class

there many applications, on use internal class c# code.

data transfer object (dto)
1 application (of many) , used many times in software, when transmitting data database application processing.
better writing internal class store data, implement useful , re-usable methods can used later in application logic (e.g isadministrator) , on.

1. object-oriented design patterns

i recommend reading book object-oriented design patterns.
books that, describe problems scenarios can implemented class using pattern. once have read these patterns , possible scenarios on can used, able book, find pattern , solve problem.

a co-worker of mine, state useful. when facing problem, should ask yourself:

"does problem solved again using design pattern?"

if answer yes, go reference book find design pattern, solve problem, without re-inventing wheel. approach, teach how , when should use separate class; maintain communication language between , co-workers, is, if talking code co-worker, able state design-pattern , understood (given that, co-worker know specific design-pattern).

2. don't afraid creating more 1 internal classes

another note, don't afraid create multiple internal classes. implement as possible, don't try implement 1 internal class , mix responsibilities. class should specific purpose, , should not more 1 thing (i.e responsibilities, if writing class transmitting data database application logic, should not - ideally - doing else, adding data database).

consider learn more polymorphism, inheritance, encapsulation , abstraction.

these 4 fundamental principles of object oriented programming can learn how structure code object-oriented.

3. general notes

as junior-developer , not junior developer in general, should willing learn more experience guys, asking feedback. not shame law of learning , improve code.

another powerful source of learning, books, consider buy area interested in. (e.g object oriented programming, design patterns etc).


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -