How to design an application keeping SOLID principles and Design Patterns in mind

左心房为你撑大大i 提交于 2019-12-11 17:16:59

问题


Say an application in ruby when started has two modes : commandline mode and filemode

When given a parameter ruby myprogram input.txt output.txt, it generates an output based on some commands in input file. also when not provided with any parameter it presents us with a command prompt. with following commands.

create_class_with_capacity 40

create_student_with_marks Alex 70

create_student_with_marks Mathew 30

create_student_with_marks John 55

..

create_student_with_marks Sylvia 70 etc...


fail_student_roll_no 12

=> Student with roll number 12 #{student} failed


give_marks_to_roll_no 70 1

=>Student with roll number 1 Alex got 70 marks


find_all_students_with_marks 70

=> Alex, Peter , Russell , Mark etc...

How to design such an application keeping RSpec,TDD , Cucumber , SOLID and Patterns in Mind. What i am directly asking is What should be Objects here to design what should be a module if applicable etc.. ? and how to gauge what needs to be tested here and what not ? Designing the most Appropriate Mechanism in terms of Object Oriented design.

Also Please Refer To some books or blogs to learn these kind of object oriented design principles and practices for ruby.


回答1:


Are you saying that you have to write this application? Is this homework?

Sounds to me like you're suffering from analysis paralysis. There are far too many buzzwords zooming around in your head.

Stop worrying about patterns and what not. Decompose the problem into pieces and start writing some code.

The one recommendation I'd make is to keep I/O out of our classes. Put all the logic that has nothing to do with interacting with users in the base classes. That way they'll still work if you're asked to create a web-based UI to replace your text version.

What has to be tested? All the code that you think might break.

The most appropriate method of object-oriented design? Do the obvious thing: nouns are potential objects in your problem statement, verbs are potential methods.

Here are some potential objects that I see: Student, Course, Roll.

Here are some potential methods: CRUD operations for Student and Course; setting grades and marking a Student as failing.

It's not that complicated. Think "simple" and get something working, then refine it.

UPDATE:

It'd be easier to answer you if you could describe what you did.

If it's the homework problem that I think it is, I doubt that it would make much difference. Rather than make us guess, why don't you read SOLID and start looking at the classes you created ask yourself if it conforms to those principles.

Patterns? Overrated. Don't worry about them.



来源:https://stackoverflow.com/questions/8286205/how-to-design-an-application-keeping-solid-principles-and-design-patterns-in-min

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!