c# - OOP - OOD - Which Method should be in which class? -


i wrote programs in procedural language (mostly vb6) since many years. learning c#. read couple of books , things done ask myself: should method in class or in class or somewhere else.

here example: write console program scans files in directory tree , set ntfs security files according rules. each “file type” (i.e. invoices, emails, excel files) have template files correct security settings.

my program following:

  1. read in myapp.exe.config log file should written

  2. start log file

  3. fill list details “file types” (currently hard coded)
  4. read in myapp.exe.config locations , filenames of template files above list
  5. more steps

i have classes program main method, filework scans through files, securitywork sets ntfs security rights, , applconfig reads , writes configuration information.

now question: should put method step 4 in above list? concerns settings securitywork class read via applconfig class. should method in securitywork class because concerns security settings, or should in applconfig class because reads information configuration file or should in program class? technically versions work , know how write them.

i know there oop principles encapsulation , others involved. looking not answer above incomplete example set of questions should ask myself decide methods concern multiple classes should be.

similar question asked , answered before of time read answers like: or that, it’s more or less you.

what suggest? maybe list questions, article or book?

to keep question within rules of stackoverflow happy read answer above example explanation of why should , not that.

a short addition question: think in many cases obvious in class method belongs. learned books because use examples straight forward.

the “how do this?” happens in cases in 2 or more classes involved , method in of these classes , program work. question then: how work best? best way keeping future amendments in mind.

i appreciate comments , answers now. thanks.

well, it's not really question stackoverflow, don't know better ask it.
example answer put method step 4 in applconfig class, , have send values it's reading securitywork class.

besides encapsulation, there's thing that's called single responsibility principle, states classes (and methods) should responsible 1 thing only.
imagine scenario want location , file names stored in database rather in app.config. keeping single responsibility principle have change 1 class , should work did before.

there lot of things said proper way decide in class method belongs, think 1 of easiest explain understand, , give answer @ least 80% of time.


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -