安卓应用程序的java编写伪代码
我正在尝试为一个安卓 GPS应用程序示例编写伪代码,我知道没有标准,但这样做是可以接受的,还是有更好、更清晰的方法
Define class MainActivity inherits Android Activity class and implements LocationListener interface
MainActivity Start
Override the void onCreate method of Activity class
start
set the buttons of the main screen layout:
do
set 'my point button' to start GeoLocation class
set 'settings button' to start Settings class
set 'address button' to start My Address class
set 'Help image_button' to start Help class
done
End
Override the void onResume method of Activity class
start
request Location Updates every 5 seconds
end
// and so on
那么代表活动生命周期呢? 它能这样表现吗
when the activity created
do ...........
done
when the activity Resumed
//and so on
然后我会写其他的课程
谢谢!
# 1 楼答案
您在这里给出的是非常具体的实现(而且,请恕我直言)。伪代码的作用是以独立于技术的方式描述实际的计算/算法,但这显然不是您想要做的。例如,在伪代码中没有抽象,这使得很容易将程序移植到C#或Objective-C,因为
Activity
之类的术语不存在你为什么需要伪代码呢
# 2 楼答案
伪代码是对算法的高级描述。因此,最好避免使用特定于语言的术语或较低级别的表达式和结构。伪代码的目标是描述一种算法,使其能够在任何语言中实现(尽可能多)
例如,避免使用
class
、implements
、void
、Override
等术语尽管(几乎)您编写的任何伪代码在技术上都是有效的,但您应该尝试遵循结构化语法,可能是您自己的或著名的语法。看看Wikipedia's page,从中得到启发
原始示例:
# 3 楼答案
使用
groovy-DSL
而不是伪代码,它甚至是可编译的(当然不是在android中)。 它比java代码更紧凑,并且提供了更高级别的抽象# 4 楼答案
我不知道你是在写伪代码,还是只是用更详细的方式写Java代码
而不是写这样的东西
你写
与从一开始就编写Java代码相比,这有什么好处
更抽象一些