10
CS 350 – Software Design CS 350 – Software Design A Problem That Cries Out for Flexible Code – A Problem That Cries Out for Flexible Code – Chapter 3 Chapter 3 Imagine you want to extract information from a CAD system to feed an Imagine you want to extract information from a CAD system to feed an expert system. expert system. I actually did something very similar to this on my coop! We wrote I actually did something very similar to this on my coop! We wrote an expert system that accessed a database and produced code that an expert system that accessed a database and produced code that generated CAD diagrams automatically. generated CAD diagrams automatically. While the expert system was object oriented, the actual code I wrote While the expert system was object oriented, the actual code I wrote was in straight C, so I had all sorts of issues that a modern was in straight C, so I had all sorts of issues that a modern programmer would not have. The CAD output was actually graphical programmer would not have. The CAD output was actually graphical instruction sheets to tell circuit board assemblers how to put instruction sheets to tell circuit board assemblers how to put together a circuit board piece by piece. We had “objects” like together a circuit board piece by piece. We had “objects” like resistors and capacitors. resistors and capacitors. In the example in the book, the idea is the same. In the example in the book, the idea is the same. They want to create a system to create stamped metal sheets with They want to create a system to create stamped metal sheets with cutouts called features. cutouts called features.

CS 350 – Software Design A Problem That Cries Out for Flexible Code – Chapter 3 Imagine you want to extract information from a CAD system to feed an expert

Embed Size (px)

DESCRIPTION

CS 350 – Software Design A Problem That Cries Out for Flexible Code – Chapter 3 Image you wanted to create the shape shown in the bottom left. Given the tools we have, you can create it in many ways. One would be to make three cuts using three features (a square and two slots.)

Citation preview

Page 1: CS 350 – Software Design A Problem That Cries Out for Flexible Code – Chapter 3 Imagine you want to extract information from a CAD system to feed an expert

CS 350 – Software DesignCS 350 – Software DesignA Problem That Cries Out for Flexible Code – Chapter 3A Problem That Cries Out for Flexible Code – Chapter 3Imagine you want to extract information from a CAD system to feed an expert Imagine you want to extract information from a CAD system to feed an expert system.system.

I actually did something very similar to this on my coop! We wrote an expert I actually did something very similar to this on my coop! We wrote an expert system that accessed a database and produced code that generated CAD system that accessed a database and produced code that generated CAD diagrams automatically. diagrams automatically.

While the expert system was object oriented, the actual code I wrote was in While the expert system was object oriented, the actual code I wrote was in straight C, so I had all sorts of issues that a modern programmer would not have. straight C, so I had all sorts of issues that a modern programmer would not have. The CAD output was actually graphical instruction sheets to tell circuit board The CAD output was actually graphical instruction sheets to tell circuit board assemblers how to put together a circuit board piece by piece. We had “objects” assemblers how to put together a circuit board piece by piece. We had “objects” like resistors and capacitors. like resistors and capacitors.

In the example in the book, the idea is the same.In the example in the book, the idea is the same.

They want to create a system to create stamped metal sheets with cutouts called They want to create a system to create stamped metal sheets with cutouts called features.features.

Page 2: CS 350 – Software Design A Problem That Cries Out for Flexible Code – Chapter 3 Imagine you want to extract information from a CAD system to feed an expert

CS 350 – Software DesignCS 350 – Software DesignA Problem That Cries Out for Flexible Code – Chapter 3A Problem That Cries Out for Flexible Code – Chapter 3SlotSlot

Straight cuts in the metal with a constant widthStraight cuts in the metal with a constant widthHoleHole

Circle cuts in the sheet metal.Circle cuts in the sheet metal.CutoutCutout

Squares with either squared or rounded edges.Squares with either squared or rounded edges.SpecialSpecial

Preformed shapes that are not slots, holes, or cutouts.Preformed shapes that are not slots, holes, or cutouts.IrregularIrregular

Anything else.Anything else.

Geometry Geometry The description of how a piece of sheet metal looks: the location of each The description of how a piece of sheet metal looks: the location of each

of the features and their dimensions and the external shape of the sheet metal.of the features and their dimensions and the external shape of the sheet metal.

PartPart The piece of sheet metal itself. The piece of sheet metal itself.

Page 3: CS 350 – Software Design A Problem That Cries Out for Flexible Code – Chapter 3 Imagine you want to extract information from a CAD system to feed an expert

CS 350 – Software DesignCS 350 – Software DesignA Problem That Cries Out for Flexible Code – Chapter 3A Problem That Cries Out for Flexible Code – Chapter 3Image you wanted to create the shape shown in the bottom left. Image you wanted to create the shape shown in the bottom left.

Given the tools we have, you can create it in many ways. One would be to make Given the tools we have, you can create it in many ways. One would be to make three cuts using three features (a square and two slots.)three cuts using three features (a square and two slots.)

Page 4: CS 350 – Software Design A Problem That Cries Out for Flexible Code – Chapter 3 Imagine you want to extract information from a CAD system to feed an expert

CS 350 – Software DesignCS 350 – Software DesignA Problem That Cries Out for Flexible Code – Chapter 3A Problem That Cries Out for Flexible Code – Chapter 3Even given the solution presented, multiple methods can be applied to create the Even given the solution presented, multiple methods can be applied to create the desired geometry.desired geometry.

A bad approach to cutting out the openings. This sequence results in weakened, A bad approach to cutting out the openings. This sequence results in weakened, bent sheet metal.bent sheet metal.

Page 5: CS 350 – Software Design A Problem That Cries Out for Flexible Code – Chapter 3 Imagine you want to extract information from a CAD system to feed an expert

CS 350 – Software DesignCS 350 – Software DesignA Problem That Cries Out for Flexible Code – Chapter 3A Problem That Cries Out for Flexible Code – Chapter 3A better approach follows that will not bend the metal as much in the process of A better approach follows that will not bend the metal as much in the process of creating it:creating it:

Page 6: CS 350 – Software Design A Problem That Cries Out for Flexible Code – Chapter 3 Imagine you want to extract information from a CAD system to feed an expert

CS 350 – Software DesignCS 350 – Software DesignA Problem That Cries Out for Flexible Code – Chapter 3A Problem That Cries Out for Flexible Code – Chapter 3This software, like most, will change over time. This software, like most, will change over time.

Interestingly in this example, there are two major components that may change: Interestingly in this example, there are two major components that may change: the expert system and the CAD system. These systems can vary independently. the expert system and the CAD system. These systems can vary independently. Either the CAD system can be upgraded or the Expert System can be enhanced.Either the CAD system can be upgraded or the Expert System can be enhanced.

The challenge is to minimize the impact one has on the other.The challenge is to minimize the impact one has on the other.

The author’s problem was he already had two CAD systems and a third was The author’s problem was he already had two CAD systems and a third was coming.coming.

Page 7: CS 350 – Software Design A Problem That Cries Out for Flexible Code – Chapter 3 Imagine you want to extract information from a CAD system to feed an expert

CS 350 – Software DesignCS 350 – Software DesignA Problem That Cries Out for Flexible Code – Chapter 3A Problem That Cries Out for Flexible Code – Chapter 3Since only one version of the expert system could use either version of CAD Since only one version of the expert system could use either version of CAD System, the CAD systems needed to look the same to the expert system.System, the CAD systems needed to look the same to the expert system.

A simple intuitive approach is depicted in the following figure:A simple intuitive approach is depicted in the following figure:

Page 8: CS 350 – Software Design A Problem That Cries Out for Flexible Code – Chapter 3 Imagine you want to extract information from a CAD system to feed an expert

CS 350 – Software DesignCS 350 – Software DesignA Problem That Cries Out for Flexible Code – Chapter 3A Problem That Cries Out for Flexible Code – Chapter 3

The expert system relates to the CAD system via the Model class.The expert system relates to the CAD system via the Model class.

The Main class instantiates the correct version of the Model.The Main class instantiates the correct version of the Model.

Page 9: CS 350 – Software Design A Problem That Cries Out for Flexible Code – Chapter 3 Imagine you want to extract information from a CAD system to feed an expert

CS 350 – Software DesignCS 350 – Software DesignA Problem That Cries Out for Flexible Code – Chapter 3A Problem That Cries Out for Flexible Code – Chapter 3Version 1 of the CAD is a library of subroutines.Version 1 of the CAD is a library of subroutines.

Here’s how it worksHere’s how it works1.1. Open model XYZ and return a handle to it.Open model XYZ and return a handle to it.2.2. Store this handle as H.Store this handle as H.3.3. For the model referred to as H, tell me how many features are present, store For the model referred to as H, tell me how many features are present, store result as N.result as N.4.4. For each feature in the model referred to by H (from 1 to N)For each feature in the model referred to by H (from 1 to N)

1.1. For the model referred to by H, tell me the ID of the ith element and store as For the model referred to by H, tell me the ID of the ith element and store as ID.ID.

2.2. For the model referred to by H, tell me the feature type of ID and store it as T.For the model referred to by H, tell me the feature type of ID and store it as T.3.3. For the model referred to by H, tell me the X coordinate of ID and store as X. For the model referred to by H, tell me the X coordinate of ID and store as X.

(Use T to determine the proper routine to call, based on type.(Use T to determine the proper routine to call, based on type.

Painful way to solve the problem.Painful way to solve the problem.No OOP.No OOP.

Page 10: CS 350 – Software Design A Problem That Cries Out for Flexible Code – Chapter 3 Imagine you want to extract information from a CAD system to feed an expert

CS 350 – Software DesignCS 350 – Software DesignA Problem That Cries Out for Flexible Code – Chapter 3A Problem That Cries Out for Flexible Code – Chapter 3Version 2 of the CAD has an object oriented implementation.Version 2 of the CAD has an object oriented implementation.

The geometry is stored as objects.The geometry is stored as objects.

The system requests a model, it is handed an object.The system requests a model, it is handed an object.

The model object contains a set of objects, each representing a feature.The model object contains a set of objects, each representing a feature.