Java 自顶向下和自底向上编程

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/881064/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 20:37:01  来源:igfitidea点击:

Top down and Bottom up programming

javac++c

提问by

Why do we say languages such as C are top-down while OOP languages like Java or C++ are bottom-up? Does this classification have any importance in software development?

为什么我们说 C 等语言是自上而下的,而 Java 或 C++ 等 OOP 语言是自下而上的?这种分类在软件开发中是否重要?

采纳答案by Charlie Martin

The "top down" approach takes a high level definition of the problem and subdivides it into subproblems, which you then do recursively until you're down to pieces that are obvious and easy to code. This is often associated with the "functional decomposition" style of programming, but needn't be.

“自上而下”的方法对问题进行高层次的定义,并将其细分为子问题,然后递归地进行,直到分解为明显且易于编码的部分。这通常与编程的“功能分解”风格相关联,但并非必须如此。

In "bottom up" programming, you identify lower-level tools that you can compose to become a bigger program.

在“自下而上”编程中,您可以确定可以组合成更大程序的较低级别的工具。

In reality, almost all programming is done with a combination of approaches. in object oriented programming, you commonly subdivide the problem by identifying domain objects (which is a top down step), and refining those, then recombining those into the final program — a bottom up step.

实际上,几乎所有的编程都是通过多种方法的组合完成的。在面向对象的编程中,您通常通过识别域对象(这是一个自上而下的步骤)并细化这些对象,然后将它们重新组合到最终程序中来细分问题——这是一个自下而上的步骤。

回答by Mohsan

C is structured language and the sequence of programs is from top to bottom. starting from the main method.

C是结构化语言,程序的顺序是从上到下的。从主方法开始。

while OOP depends upon number of classes and objects. flow of program is not in top down approach in OOP

而 OOP 取决于类和对象的数量。OOP中的程序流不是自上而下的方法

回答by Vini

This Wikipedia page explains it pretty well http://en.wikipedia.org/wiki/Top-down#Programming

这个维基百科页面很好地解释了它http://en.wikipedia.org/wiki/Top-down#Programming

回答by Eclipse

In Top-Down development you start out with your main function, and then think of the main steps you need to take, then you break up each of those steps into their subparts, and so on.

在自上而下的开发中,您从主要功能开始,然后考虑需要采取的主要步骤,然后将每个步骤分解为子部分,依此类推。

In Bottom-Up programming you think of the basic functionality and the parts you're going to need and build them up. You develop the actors and their methods, and then you tie them together to make a coherent whole.

在自下而上编程中,您会考虑基本功能和您将需要的部件,然后将它们构建起来。你开发演员和他们的方法,然后你把他们联系在一起,形成一个连贯的整体。

OOP naturally tends toward Bottom-Up as you develop your objects, while procedural programming tends toward Top-Down as you start out with one function and slowly add to it.

当您开发对象时,OOP 自然倾向于自下而上,而当您从一个函数开始并慢慢添加时,过程编程倾向于自上而下。

回答by AviD

I've never heard that classification applied to specific languages, rather it's a programming paradigm - do you first fill out the details (i.e. build full implementation methods) and then put them together (e.g. call them from them main() method), or start with the logical flow and then flesh out the implementation?

我从来没有听说过分类应用于特定语言,而是一种编程范式——你是先填写细节(即构建完整的实现方法),然后将它们放在一起(例如从它们的 main() 方法中调用它们),还是从逻辑流程开始,然后充实实现?

You can really do either with both types of lanugages... But I would say it's typically the opposite, in current OOP languages you'll first define the interfaces, forming the logical structure, and only afterwards worry about the implementation, whereas straight procedural languages like C, you need to actually implement some methods before you call them.

你真的可以用两种类型的语言来做任何一种......但我会说这通常是相反的,在当前的 OOP 语言中,你将首先定义接口,形成逻辑结构,然后才担心实现,而直接程序像 C 这样的语言,你需要在调用它们之前实际实现一些方法。

回答by Nat

I've never heard the terms "top-down" and "bottom-up" used in that way.

我从未听说过以这种方式使用的术语“自上而下”和“自下而上”。

The terms are usually used to describe how one approaches design and implementation of a software system and so apply to any language or programming paradigm.

这些术语通常用于描述一个软件系统的设计和实现方法,因此适用于任何语言或编程范式。

In "On LISP", Paul Graham uses the term "bottom-up" slightly differently to mean continually extracting common functionality into shared functions so that you end up creating a new, higher level dialect of LISP that lets you program in terms of your application domain. That's not a common use of the term. These days we would call that "refactoring" and "domain-specific embedded languages" (and old LISP programmers would sneer that LISP has been able to do that since the 1950s).

在“On LISP”中,Paul Graham 使用的术语“自下而上”略有不同,意思是不断地将通用功能提取到共享函数中,以便您最终创建一种新的、更高级别的 LISP 方言,让您可以根据应用程序进行编程领域。这不是该术语的常见用法。如今,我们将其称为“重构”和“特定领域的嵌入式语言”(老 LISP 程序员会嘲笑 LISP 自 1950 年代以来就能够做到这一点)。

回答by Rytek

It's more about paradigm (object oriented, imperative, functionnal etc.) than syntax.

它更多地是关于范式(面向对象、命令式、函数式等)而不是语法。

From dept-info.labri.fr

来自dept-info.labri.fr

Bottom-up programming is the opposite of top-down programming. It refers to a style of programming where an application is constructed starting with existing primitives of the programming language, and constructing gradually more and more complicated features, until the all of the application has been written.

自底向上编程与自顶向下编程相反。它指的是一种编程风格,从编程语言的现有原语开始构建应用程序,逐渐构建越来越复杂的功能,直到编写了所有应用程序。

Later in the same article :

在同一篇文章的后面:

In a language such as C or Java, bottom-up programming takes the form of constructing abstract data types from primitives of the language or from existing abstract data types.

在诸如 C 或 Java 之类的语言中,自底向上编程的形式是从语言的原语或现有的抽象数据类型构造抽象数据类型。

回答by varinder

In top-down approach the system is first formulated specifying but not detailing any subsystem at the beginning, and then each system and its subsystem is defined in great detail until specifying it to the base.

在自上而下的方法中,系统首先在开始时指定但不详细说明任何子系统,然后非常详细地定义每个系统及其子系统,直到将其指定给基础。

e.g.- In a C program one needs to declare functions at the top of the program and then through the main entry to every subsystem/subroutine is defined in great detail.

例如,在 C 程序中,需要在程序顶部声明函数,然后通过主条目详细定义每个子系统/子例程。

In bottom-up approach first designing, beginning from the base level to the abstract level is done.

在自底向上的方法第一次设计中,从基础级别开始到抽象级别完成。

e.g.-In c++/java starts designing from class from basic level of the programming features and then goes to the main part of the program.

eg-In c++/java 从编程功能的基本级别开始从类开始设计,然后进入程序的主要部分。

回答by Xcode

I do believe the difference between the top down approach and bottom up approach to programming is that the top down approach takes the problem and into and breaks into manageable steps and bottom up approach is actually detailing those steps.

我确实相信自上而下的方法和自下而上的编程方法之间的区别在于,自上而下的方法解决问题并分解为可管理的步骤,而自下而上的方法实际上详细说明了这些步骤。

回答by Vivek

Most of the procedural or low level languages follow Top-down approach like C language.Similarly high level languages like java ,c++ etc follows Bottom-Up Approach.

大多数过程或低级语言都遵循自顶向下的方法,如 C 语言。类似的高级语言,如 java、c++ 等遵循自底向上的方法。

In Top-down approach,all the system or big functions are broken down into small subsystem whereas in Bottom-up approach,Small sub-system are combined together to develop a big and final system.

在自上而下的方法中,所有系统或大功能都被分解为小子系统,而在自下而上的方法中,小子系统组合在一起形成一个大的和最终的系统。

e.g.Recursive is top down approach while Iterative is Bottom up approach.

egRecursive 是自顶向下的方法,而 Iterative 是自底向上的方法。