OOP仿照在驱动应用一个数据库对象? [英] OOP Modelled Objects in a Database Driven App?

查看:108
本文介绍了OOP仿照在驱动应用一个数据库对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经建立了一个基于SQLite数据库对整个银行应用程序。今天,我有一个恐慌的时刻。我一直在阅读各种关于OOP的文章,我相信我理解这个概念,它的重要性,但是,我不明白它发生在像我一样的应用程序。到目前为止,也许是无知,我的处理数据逻辑已被如下(编辑一个新帐户申请银行表例如伪code):

I've built an entire banking app based on a SQLite database. Today I'm having a panic moment. I've been reading all sorts of articles on OOP, I believe I understand the concept and it's importance, however, I can't understand its place in an app like mine. So far, perhaps ignorantly, my logic for dealing with data has been as follows (example pseudo code for editing a banking form for a new account application):


  • 在EditAccountApplication活动,定义一个公共光标,此光标将举办之前申请表数据的详细信息。

  • 查询数据库的使用从DbHelper的方法旧的申请表数据,返回一个Cursor对象与上述数据。

  • 使用此光标,填充UI组件(的EditText,TextView的,等等),使用户可以编辑与更新的数据重新提交其应用价值。

  • 用户点击按钮重新递交申请表,在按钮的onClick()方法中,变量的定义,并为每个UI组件设置在ContentValues​​对象,ContentValues​​对象随后被传递回DbHelper的方法,最终更新有关的数据库记录。

这是正确的做法,我应该用一个SQLite后端时服用?我没有看到如何建模对象会在这种情况下帮助(光标pretty多的对象,我不需要操作它的UI元素可供用户操作)。

Is this the correct approach I should be taking when using a SQLite backend? I am not seeing how modelling objects would help in this case (the Cursor is pretty much the object, I don't need to manipulate it as the UI elements are available for the user to manipulate).

我真的希望了解这种情况是否之一,创建建模的对象是没有额外的好处。

I really wish to understand whether or not this situation is one where creating modelled objects is of no added benefit.

我真的AP preciate任何帮助,现实检查将在这一点上是一种解脱,因为我吓坏了!

I really appreciate any help, a reality check will be a relief at this point as I'm freaking out!

再次感谢!

推荐答案

您已经使用OOP没有被意识到这一点。当编写一个平台如Android移动应用程序,你平时用做普通任务常见的模式(如更新一个SQLite后端)。这些模式在那里无论是Android开发页面上,还是在片段的书籍和很具体。因此很难从他们偏离 - 他们是已经面向对象

You are already using OOP without being conscious of it. When programming a mobile app for a platform such as Android, you usually use common patterns for doing common tasks (such as updating a Sqlite backend). These patterns are out there either on the Android Dev page, or in snippets in books and are very specific. So it's hard to deviate from them - and they are "already" object oriented.

现在,假设你在你的应用程序中保持一个银行账户对象的实例在内存中,因此需要MODELA的BankAccount对象。在那里,你可以遵循OOP原则,如封装和数据例如通过隐藏有一个方法:

Now, let's say you were keeping instances of a bank account object in memory in your app and hence needed to modela BankAccount object. There you could follow OOP principles such as encapsulation and data hiding by for example having a method:

debitAccount(double amt) {
  // do validation checks for account balance such as don't let it go negative
}

在BankAccount类和操纵的。或者,如果你暴露了更新的对象,并有听众该更新,必须予以通知的API,那么你必须使用观察者模式明​​确造型OOP的机会。

in the BankAccount class and manipulating that. Or if you were exposing an API that updated objects and there were listeners to that update that had to be notified, then you have a chance of explicitly modelling OOP using the Observer pattern.

但是,对于一个简单的任务,如更新SQLite数据库,当你使用特定的Andr​​oid模式,如您正在使用中,code已经面向对象的。

But for a simple task such as updating a SQLite database, when you use a specific Android pattern such as you are using, the code is ALREADY Object Oriented.

恕我直言,你是好人。

这篇关于OOP仿照在驱动应用一个数据库对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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