如何设计一个保持SOLID原则和设计模式的应用程序 [英] How to design an application keeping SOLID principles and Design Patterns in mind

查看:314
本文介绍了如何设计一个保持SOLID原则和设计模式的应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在ruby中说一个应用程序有两种模式:命令行模式和文件模式



当给定一个参数,它会根据输入文件中的某些命令生成输出。当没有提供任何参数,它给我们一个命令提示符。具有以下命令。

  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

=>卷号为12的学生#{student}失败


give_marks_to_roll_no 70 1

=>卷号为1的学生Alex有70分


find_all_students_with_marks 70

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

如何设计这样的应用程序保存RSpec,TDD ,黄瓜,固体和模式。
我直接问的是什么应该是对象这里设计什么应该是一个模块,如果适用等。以及如何衡量什么需要在这里测试什么?在面向对象设计方面设计最适当的机制。



另请参阅一些书籍或博客,了解这些面向对象设计原则和实践的ruby。

解决方案

你是说要写这个应用吗?这是家庭作业吗?



听起来像我一样,患有分析瘫痪。



不要担心模式,不要担心模式。将问题分解成碎片并开始编写一些代码。



我建议的一个建议是将I / O保留在我们的类中。放置所有与在基类中与用户交互无关的逻辑。这样,如果您被要求创建一个基于Web的UI来替换您的文本版本,它们仍然可以工作。



需要测试什么?所有您认为可能破裂的代码。



面向对象设计的最合适的方法?做明显的事情:名词是你的问题陈述中的潜在对象,动词是潜在的方法。



这里是我看到的一些潜在对象:Student,Course,Roll。 / p>

这里有一些可能的方法:CRUD操作的学生和课程;设置成绩并将学生标记为失败。



这不是那么复杂。



更新:



回答你,如果你能描述你做了什么。



如果这是家庭作业问题,我认为是,我怀疑它会有很大的区别。而不是让我们猜测,为什么不阅读SOLID,并开始看你创建的类问自己是否符合这些原则。



模式?被高估。不要担心他们。


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.

解决方案

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.

这篇关于如何设计一个保持SOLID原则和设计模式的应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆