5 Steps to a 5 AP Computer Science A 2017 (2016)

STEP 4

Review the Knowledge You Need to Score High

CONCEPT 13

Seeing the Big Picture: Design

IN THIS CONCEPT

Summary: If you take a bird’s eye view of the idea of software development, you can see that it is important for programmers to follow guidelines. The rules that guide programmers help make sure that programs are easily maintainable.

Key Ideas

   Program specifications define what a program is supposed to accomplish.

   Someone other than the software developer often writes program specifications.

   Software engineering is a field that studies how software is designed, developed, and maintained.

   Top-down and bottom-up are two approaches to designing class hierarchy.

   Procedural abstraction helps make software more modular.

   Software developers use testing techniques to verify that their program is working correctly.

The Software Development Cycle

Program Specifications

When you are in computer science class, your teacher probably gives you assignments that have program specifications . This means that in order to receive full credit for the assignment, you have to follow the directions and make sure that your program does what it is supposed to do. When you write your own programs for your own purpose, you make your own specifications.

In the real world of programming, it is common for someone from a design team to give the software developers the program specifications. Specifications are descriptions of what the program should look like and how it should operate. Someone other than the actual programmer writes these specs . You may have heard that it is important to be a good communicator. Well, great programmers have good communication skills so that they can talk back and forth with the person who writes the specs to clarify any questions they may have.

Working for Others

Programmers must learn how to write code from specifications. On the Free-Response Questions section of the AP Computer Science A Exam, you have to write code that matches the specifications that are described in the questions.

Software Engineering

Software engineering is the study of designing, developing, and maintaining software.

Over the years, many different software development models have been designed that help developers create quality software. Here is a brief list.

  • Prototyping—an approximation of a final system is built, tested, and reworked until it is acceptable. The complete system is then developed from this prototype.
  • Incremental development—The software is designed, implemented, and tested a little bit at a time until the product is finished.
  • Rapid application development—the user is actively involved in the evaluation of the product and modifications are made immediately as problems are found. Radical changes in the system are likely at any moment in the process.
  • Agile software development—the developers offer frequent releases of the software to the customer and new requirements are generated by the users. Short development cycles are common in this type of development.
  • Waterfall model—the progress of development is sequential and flows downward like a waterfall. Steps include conception, initiation, analysis, design, construction, testing, implementation, and maintenance.

Fun Fact: Margaret Hamilton, a computer scientist who helped develop the on-board flight software for the Apollo space program, coined the phrase “software engineering.” Her code prevented an abort of a moon landing!

So What’s the Best Way?

It depends on the situation. It varies from problem to problem, situation to situation, and even company to company. My belief is that you should view the models of software engineering as tools in a toolbox in which the technique that you apply depends on the project you are working on.

Designing Class Hierarchy

Top-Down Versus Bottom-Up Design

Top-down and bottom-up are two ways of approaching class hierarchy design. Top-down is also referred to as functional decomposition . The two designs are different only in their approach to the problem. Top-down design starts with the big picture, whereas a bottom-up design starts with the details. They each work toward the other, but where they begin is different.

Top-Down Versus Bottom-Up in Object-Oriented Programming

This concept can be applied to designing a complex class hierarchy. If you start your design by thinking of what would be at the top of the class hierarchy, then you are doing a top-down design. If you start your design by thinking of what would be at the bottom of the class hierarchy, then you are doing a bottom-up design.

For example, suppose you have been given the opportunity to design a video game for the NFL (National Football League). If you approach the design from a bottom-up perspective, you would say, “Let’s design the Player class first. We’ll determine all the instance variables and methods for the Player. Then we’ll move on to the Team class. After we get those done, we’ll figure out where to go from there.” This approach starts with the lowest level object that could be in your game first (the Player), and then works up from there.

If you approach the design from a top-down perspective, you would say, “Let’s design the League class first. We’ll identify what every League has and what it can do. Then, we’ll move onto the Conference class. After we get those done, we’ll figure out where to go from there.” This approach starts with the highest possible object first (the League), and then works down from there.

Top-Down Versus Bottom-Up

Top-down design begins with the parent classes, while bottom-up starts with the child classes. On the AP Computer Science A Exam, you will need to be able to recognize a top-down versus a bottom-up design.

Procedural Abstraction

When a program is broken down into pieces and each piece has a responsibility, then the program is following procedural abstraction . For example, if you write a quest game and have separate methods for hunting, gathering, and collecting, then you are following procedural abstraction. If your hunt method also gathers, collects, and slays dragons while eating a peanut butter and jelly sandwich, then you are not following procedural abstraction.

Fun Fact: The word procedure comes from early procedural programming languages like Fortran and Pascal. Procedures are similar to methods in Java. Each procedure has a purpose and does its job when you ask it to .

Procedural Abstraction

Every method in Java should have a specific job. Complex tasks should be broken down into smaller tasks.

Testing

You may have heard of video game testers whose job it is to find bugs in the software. Talk about a dream job, right? Well, professional programmers test their work to make sure that it does what it’s supposed to do before they release it. There are a few standard ways that developers test code.

Unit Testing

Unit tests are typically short methods that test whether or not a specific method is performing its task correctly. Suppose you have a method that performs some kind of mathematical calculation. To test if this method is working correctly, you would write another method, called a unit test . The unit test calls the method you want to test to see if it is producing correct answers. To accomplish this, you figure out what the answer is before you make the call to the method and compare the method’s answer with your answer.

Here are the steps to creating a unit test for a method:

  1. Create a method that performs some kind of calculation.
  2. Think of an appropriate input for the method and calculate the answer.
  3. Create a unit test. The unit test must contain a call to the original method.
  4. Run the unit test with your input and compare the result to the answer you calculated.
  5. Repeat this process for every possible type of input that you can think of. For example, when creating a unit test method that does a mathematical calculation, you may want to test it with a positive number, a negative number, and zero.
  6. If the method produces correct values for every one of your inputs, the method passes the unit test .

Example

Create a unit test method for the getArea method of the Circle class from Concept 2. Pass it a value for the radius as well as the known answer for its area to determine if the method is doing its calculation correctly.

Integration Testing

Integration testing is used to make sure that connections to outside resources are working correctly. For example, if you are writing software that connects to Snapchat, then you would write a method that tests whether the connection is made correctly.

 Rapid Review

  • Program specifications define what a program is supposed to accomplish.
  • Someone other than the software developer often writes program specifications.
  • A good software developer has the ability to communicate with others.
  • Software engineering is a field that studies how software is designed, developed, and maintained.
  • There isn’t one correct way to design a computer program. How you write the program depends on the application.
  • Top-down and bottom-up are two approaches to designing class hierarchy.
  • Top-down design starts with the parent classes and works toward the child classes.
  • Bottom-up design starts with the child classes and works toward the parent classes.
  • Procedural abstraction helps make software more modular.
  • When applying procedural abstraction to a complex task, the developer breaks the complex task down into smaller parts and implements these tasks individually.
  • Software developers use testing techniques to verify that their program is working correctly.
  • Unit testing is the process of testing a method to make sure that it is working correctly.
  • Integration testing is the process of testing connections to outside resources to make sure that they are working correctly.

 Review Questions

1 .    You are designing a program to simulate the students at your school. Starting with which one of these classes would best demonstrate top-down design?

(A)   The student body

(B)   The senior class

(C)   The girls in the senior class

(D)   The girls taking programming in the senior class

(E)   Mary Zhang, a girl in the programming class

2 .    If you were designing a unit test for the isEven method, which of these methods would you prefer to be working with and why? Note that the two methods both work and return the same result.

Option 1:

Option 2:

(A)   Option 1 because it doesn’t use modulus, so it’s easier to understand.

(B)   Option 1 because it is longer.

(C)   Option 2 because there is only one path through the code, so fewer test cases are needed.

(D)   Neither option requires testing because the intent of the method is clear from the name.

(E)   It doesn’t matter. Testing them would be the same.

3 .    What is the term used to describe breaking a large program into smaller, well-defined sections that are easier to code and maintain?

(A)   Encapsulation

(B)   Procedural abstraction

(C)   Inheritance

(D)   Static design

(E)   Polymorphism

 Answers and Explanations

1 .    The answer is A.

In top-down design, you start by designing the broadest category, and then work your way down. The broadest category here is the student body.

2 .    The answer is C.

Unit tests have to test every path through the code. The fewer the paths, the shorter the test, the more sure the tester is that the code will work in every case.

3 .    The answer is B.

This process is called procedural abstraction.







All materials on the site are licensed Creative Commons Attribution-Sharealike 3.0 Unported CC BY-SA 3.0 & GNU Free Documentation License (GFDL)

If you are the copyright holder of any material contained on our site and intend to remove it, please contact our site administrator for approval.

© 2016-2024 All site design rights belong to S.Y.A.