首页 \ 问答 \ 这是Crudy反模式吗?(Is this the Crudy anti pattern?)

这是Crudy反模式吗?(Is this the Crudy anti pattern?)

目前我正在创建一个WCF服务,它必须连接到DAL,它只使用ADO.net和存储过程连接到数据库。

DAl将其数据库的响应写入数据传输,数据传输通过服务传递到客户端。

我读到这可能是反模式'CRudy接口',但我不确定,因为我正在分享数据合同。

如果我使用反模式,任何人都可以建议一个更好的模式用于我需要的行为吗?


Currently I am creating a WCF service which has to connect to a DAL which, just connects to a database using ADO.net and stored procedures.

The DAl writes its responses from the database to a datacontract which is passed over the wire to the client via the service.

I was reading that this may possibly be the anti pattern 'CRudy Interface', but I wasn't sure as I am sharing the datacontract.

If I am using an anti pattern, can anyone suggest a better pattern to use for the behavior I require?


原文:https://stackoverflow.com/questions/2452860
更新时间:2022-01-08 09:01

最满意答案

这是一个你可以玩的应用程序来弄清楚你做错了什么。

主要:

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;

/**
 *
 * @author blj0011
 */
public class CollisionDection extends Application {

    @Override
    public void start(Stage stage) throws Exception {
        Parent root = FXMLLoader.load(getClass().getResource("FXMLDocument.fxml"));

        Scene scene = new Scene(root);

        stage.setScene(scene);
        stage.show();
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        launch(args);
    }

}

控制器:

import java.net.URL;
import java.util.ResourceBundle;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.SimpleObjectProperty;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.geometry.Point2D;
import javafx.scene.control.Label;
import javafx.scene.input.MouseEvent;
import javafx.scene.shape.Circle;
import javafx.scene.shape.Polygon;
import javafx.scene.shape.Rectangle;
import javafx.scene.shape.Shape;

/**
 *
 * @author sedj601
 */
public class FXMLDocumentController implements Initializable {

    @FXML private Label lblMain;
    @FXML private Polygon polyOne, polyTwo;    
    @FXML private Circle circle1;
    @FXML private Rectangle rectangle1;

    final ObjectProperty<Point2D> mousePosition = new SimpleObjectProperty<>();

    @Override
    public void initialize(URL url, ResourceBundle rb) {
        // TODO
        polyOne.setOnMousePressed((MouseEvent event) -> {
            mousePosition.set(new Point2D(event.getSceneX(), event.getSceneY()));
        });

        polyOne.setOnMouseDragged((MouseEvent event) -> {
            double deltaX = event.getSceneX() - mousePosition.get().getX();
            double deltaY = event.getSceneY() - mousePosition.get().getY();
            polyOne.setLayoutX(polyOne.getLayoutX()+deltaX);
            polyOne.setLayoutY(polyOne.getLayoutY()+deltaY);
            mousePosition.set(new Point2D(event.getSceneX(), event.getSceneY()));

            Shape intersect = Shape.intersect(polyOne, polyTwo);

            if(intersect.getBoundsInLocal().getWidth() != -1)
            {
                System.out.println("This object can overlap other the other object!");
                lblMain.setText("Collision detected!");
            }
            else
            {
                intersect.getBoundsInLocal().getWidth();
                lblMain.setText("Collision not detected!");
            }            
        });

        polyTwo.setOnMousePressed((MouseEvent event) -> {
            mousePosition.set(new Point2D(event.getSceneX(), event.getSceneY()));
        });

        polyTwo.setOnMouseDragged((MouseEvent event) -> {
            double deltaX = event.getSceneX() - mousePosition.get().getX();
            double deltaY = event.getSceneY() - mousePosition.get().getY();
            polyTwo.setLayoutX(polyTwo.getLayoutX() + deltaX);
            polyTwo.setLayoutY(polyTwo.getLayoutY() + deltaY);
            mousePosition.set(new Point2D(event.getSceneX(), event.getSceneY()));

            Shape intersect = Shape.intersect(polyOne, polyTwo);
            {
                if(intersect.getBoundsInLocal().getWidth() != -1)
                {      
                    System.out.println("This object can not overlap other the other object!");
                    polyTwo.setLayoutX(polyTwo.getLayoutX() - deltaX);
                    polyTwo.setLayoutY(polyTwo.getLayoutY() - deltaY);
                    lblMain.setText("Collision detected!");
                }
                else
                {
                    lblMain.setText("Collision not detected!");
                }
            }
        });   

        circle1.setOnMousePressed((MouseEvent event) -> {
            mousePosition.set(new Point2D(event.getSceneX(), event.getSceneY()));
        });

        circle1.setOnMouseDragged((MouseEvent event) -> {
            double deltaX = event.getSceneX() - mousePosition.get().getX();
            double deltaY = event.getSceneY() - mousePosition.get().getY();
            circle1.setLayoutX(circle1.getLayoutX() + deltaX);
            circle1.setLayoutY(circle1.getLayoutY() + deltaY);
            mousePosition.set(new Point2D(event.getSceneX(), event.getSceneY()));

            Shape intersect = Shape.intersect(rectangle1, circle1);
            {
                if(intersect.getBoundsInLocal().getWidth() != -1)
                {      
                    System.out.println("This object can not overlap other the other object!");
                    circle1.setLayoutX(circle1.getLayoutX() - deltaX);
                    circle1.setLayoutY(circle1.getLayoutY() - deltaY);
                    lblMain.setText("Collision detected!");
                }
                else
                {
                    lblMain.setText("Collision not detected!");
                }
            }
        });   


        rectangle1.setOnMousePressed((MouseEvent event) -> {
            mousePosition.set(new Point2D(event.getSceneX(), event.getSceneY()));
        });

        rectangle1.setOnMouseDragged((MouseEvent event) -> {
            double deltaX = event.getSceneX() - mousePosition.get().getX();
            double deltaY = event.getSceneY() - mousePosition.get().getY();
            rectangle1.setLayoutX(rectangle1.getLayoutX() + deltaX);
            rectangle1.setLayoutY(rectangle1.getLayoutY() + deltaY);
            mousePosition.set(new Point2D(event.getSceneX(), event.getSceneY()));

            Shape intersect = Shape.intersect(circle1, rectangle1);
            {
                if(intersect.getBoundsInLocal().getWidth() != -1)
                {      
                    System.out.println("This object can not overlap other the other object!");
                    rectangle1.setLayoutX(rectangle1.getLayoutX() - deltaX);
                    rectangle1.setLayoutY(rectangle1.getLayoutY() - deltaY);
                    lblMain.setText("Collision detected!");
                }
                else
                {
                    lblMain.setText("Collision not detected!");
                }
            }
        });   
    }
}

FXML:

<AnchorPane id="AnchorPane" fx:id="apMain" prefHeight="446.0" prefWidth="577.0" xmlns="http://javafx.com/javafx/8.0.111" xmlns:fx="http://javafx.com/fxml/1" fx:controller="collisiondection.FXMLDocumentController">
    <children>
        <Label fx:id="lblMain" layoutX="254.0" layoutY="408.0" minHeight="16" minWidth="69" />
      <Polygon fx:id="polyOne" fill="DODGERBLUE" layoutX="122.0" layoutY="166.0" stroke="BLACK" strokeType="INSIDE">
        <points>
          <Double fx:value="-50.0" />
          <Double fx:value="40.0" />
          <Double fx:value="50.0" />
          <Double fx:value="40.0" />
          <Double fx:value="0.0" />
          <Double fx:value="-60.0" />
        </points>
      </Polygon>
      <Polygon fx:id="polyTwo" fill="DODGERBLUE" layoutX="419.0" layoutY="166.0" stroke="BLACK" strokeType="INSIDE">
        <points>
          <Double fx:value="-50.0" />
          <Double fx:value="40.0" />
          <Double fx:value="50.0" />
          <Double fx:value="40.0" />
          <Double fx:value="0.0" />
          <Double fx:value="-60.0" />
        </points>
      </Polygon>
      <Circle fx:id="circle1" fill="DODGERBLUE" layoutX="113.0" layoutY="372.0" radius="42.0" stroke="BLACK" strokeType="INSIDE" />
      <Rectangle fx:id="rectangle1" arcHeight="5.0" arcWidth="5.0" fill="DODGERBLUE" height="100.0" layoutX="379.0" layoutY="314.0" stroke="BLACK" strokeType="INSIDE" width="113.0" />
    </children>
</AnchorPane>

Here is an app you can play with to figure out what you did wrong.

Main:

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;

/**
 *
 * @author blj0011
 */
public class CollisionDection extends Application {

    @Override
    public void start(Stage stage) throws Exception {
        Parent root = FXMLLoader.load(getClass().getResource("FXMLDocument.fxml"));

        Scene scene = new Scene(root);

        stage.setScene(scene);
        stage.show();
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        launch(args);
    }

}

Controller:

import java.net.URL;
import java.util.ResourceBundle;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.SimpleObjectProperty;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.geometry.Point2D;
import javafx.scene.control.Label;
import javafx.scene.input.MouseEvent;
import javafx.scene.shape.Circle;
import javafx.scene.shape.Polygon;
import javafx.scene.shape.Rectangle;
import javafx.scene.shape.Shape;

/**
 *
 * @author sedj601
 */
public class FXMLDocumentController implements Initializable {

    @FXML private Label lblMain;
    @FXML private Polygon polyOne, polyTwo;    
    @FXML private Circle circle1;
    @FXML private Rectangle rectangle1;

    final ObjectProperty<Point2D> mousePosition = new SimpleObjectProperty<>();

    @Override
    public void initialize(URL url, ResourceBundle rb) {
        // TODO
        polyOne.setOnMousePressed((MouseEvent event) -> {
            mousePosition.set(new Point2D(event.getSceneX(), event.getSceneY()));
        });

        polyOne.setOnMouseDragged((MouseEvent event) -> {
            double deltaX = event.getSceneX() - mousePosition.get().getX();
            double deltaY = event.getSceneY() - mousePosition.get().getY();
            polyOne.setLayoutX(polyOne.getLayoutX()+deltaX);
            polyOne.setLayoutY(polyOne.getLayoutY()+deltaY);
            mousePosition.set(new Point2D(event.getSceneX(), event.getSceneY()));

            Shape intersect = Shape.intersect(polyOne, polyTwo);

            if(intersect.getBoundsInLocal().getWidth() != -1)
            {
                System.out.println("This object can overlap other the other object!");
                lblMain.setText("Collision detected!");
            }
            else
            {
                intersect.getBoundsInLocal().getWidth();
                lblMain.setText("Collision not detected!");
            }            
        });

        polyTwo.setOnMousePressed((MouseEvent event) -> {
            mousePosition.set(new Point2D(event.getSceneX(), event.getSceneY()));
        });

        polyTwo.setOnMouseDragged((MouseEvent event) -> {
            double deltaX = event.getSceneX() - mousePosition.get().getX();
            double deltaY = event.getSceneY() - mousePosition.get().getY();
            polyTwo.setLayoutX(polyTwo.getLayoutX() + deltaX);
            polyTwo.setLayoutY(polyTwo.getLayoutY() + deltaY);
            mousePosition.set(new Point2D(event.getSceneX(), event.getSceneY()));

            Shape intersect = Shape.intersect(polyOne, polyTwo);
            {
                if(intersect.getBoundsInLocal().getWidth() != -1)
                {      
                    System.out.println("This object can not overlap other the other object!");
                    polyTwo.setLayoutX(polyTwo.getLayoutX() - deltaX);
                    polyTwo.setLayoutY(polyTwo.getLayoutY() - deltaY);
                    lblMain.setText("Collision detected!");
                }
                else
                {
                    lblMain.setText("Collision not detected!");
                }
            }
        });   

        circle1.setOnMousePressed((MouseEvent event) -> {
            mousePosition.set(new Point2D(event.getSceneX(), event.getSceneY()));
        });

        circle1.setOnMouseDragged((MouseEvent event) -> {
            double deltaX = event.getSceneX() - mousePosition.get().getX();
            double deltaY = event.getSceneY() - mousePosition.get().getY();
            circle1.setLayoutX(circle1.getLayoutX() + deltaX);
            circle1.setLayoutY(circle1.getLayoutY() + deltaY);
            mousePosition.set(new Point2D(event.getSceneX(), event.getSceneY()));

            Shape intersect = Shape.intersect(rectangle1, circle1);
            {
                if(intersect.getBoundsInLocal().getWidth() != -1)
                {      
                    System.out.println("This object can not overlap other the other object!");
                    circle1.setLayoutX(circle1.getLayoutX() - deltaX);
                    circle1.setLayoutY(circle1.getLayoutY() - deltaY);
                    lblMain.setText("Collision detected!");
                }
                else
                {
                    lblMain.setText("Collision not detected!");
                }
            }
        });   


        rectangle1.setOnMousePressed((MouseEvent event) -> {
            mousePosition.set(new Point2D(event.getSceneX(), event.getSceneY()));
        });

        rectangle1.setOnMouseDragged((MouseEvent event) -> {
            double deltaX = event.getSceneX() - mousePosition.get().getX();
            double deltaY = event.getSceneY() - mousePosition.get().getY();
            rectangle1.setLayoutX(rectangle1.getLayoutX() + deltaX);
            rectangle1.setLayoutY(rectangle1.getLayoutY() + deltaY);
            mousePosition.set(new Point2D(event.getSceneX(), event.getSceneY()));

            Shape intersect = Shape.intersect(circle1, rectangle1);
            {
                if(intersect.getBoundsInLocal().getWidth() != -1)
                {      
                    System.out.println("This object can not overlap other the other object!");
                    rectangle1.setLayoutX(rectangle1.getLayoutX() - deltaX);
                    rectangle1.setLayoutY(rectangle1.getLayoutY() - deltaY);
                    lblMain.setText("Collision detected!");
                }
                else
                {
                    lblMain.setText("Collision not detected!");
                }
            }
        });   
    }
}

FXML:

<AnchorPane id="AnchorPane" fx:id="apMain" prefHeight="446.0" prefWidth="577.0" xmlns="http://javafx.com/javafx/8.0.111" xmlns:fx="http://javafx.com/fxml/1" fx:controller="collisiondection.FXMLDocumentController">
    <children>
        <Label fx:id="lblMain" layoutX="254.0" layoutY="408.0" minHeight="16" minWidth="69" />
      <Polygon fx:id="polyOne" fill="DODGERBLUE" layoutX="122.0" layoutY="166.0" stroke="BLACK" strokeType="INSIDE">
        <points>
          <Double fx:value="-50.0" />
          <Double fx:value="40.0" />
          <Double fx:value="50.0" />
          <Double fx:value="40.0" />
          <Double fx:value="0.0" />
          <Double fx:value="-60.0" />
        </points>
      </Polygon>
      <Polygon fx:id="polyTwo" fill="DODGERBLUE" layoutX="419.0" layoutY="166.0" stroke="BLACK" strokeType="INSIDE">
        <points>
          <Double fx:value="-50.0" />
          <Double fx:value="40.0" />
          <Double fx:value="50.0" />
          <Double fx:value="40.0" />
          <Double fx:value="0.0" />
          <Double fx:value="-60.0" />
        </points>
      </Polygon>
      <Circle fx:id="circle1" fill="DODGERBLUE" layoutX="113.0" layoutY="372.0" radius="42.0" stroke="BLACK" strokeType="INSIDE" />
      <Rectangle fx:id="rectangle1" arcHeight="5.0" arcWidth="5.0" fill="DODGERBLUE" height="100.0" layoutX="379.0" layoutY="314.0" stroke="BLACK" strokeType="INSIDE" width="113.0" />
    </children>
</AnchorPane>

相关问答

更多
  • 最好用几个图说明: 有入射角=反射角。 将此值称为θ。 θ=法线角度 - 入射角度。 atan2是用于计算来自正x轴的矢量角度的函数。 然后紧接着是下面的代码: function collision(rect, circle){ var NearestX = Max(rect.x, Min(circle.pos.x, rect.x + rect.w)); var NearestY = Max(rect.y, Min(circle.pos.y, rect.y + rect.h)); var di ...
  • 你必须调用obPrimeStage.show(); 在使用Scene的.getWidth()之前。 public class Question4 extends Application { public int carRightSide = 80; @Override public void start( Stage obPrimeStage ) throws Exception { Pane obPane = new Pane(); ...
  • 这是一个你可以玩的应用程序来弄清楚你做错了什么。 主要: import javafx.application.Application; import javafx.fxml.FXMLLoader; import javafx.scene.Parent; import javafx.scene.Scene; import javafx.stage.Stage; /** * * @author blj0011 */ public class CollisionDection extends Applic ...
  • 我终于设法让它在各方面都有效。 首先,我通过检查球的中心与任何角落之间的距离是否小于/等于球的半径来计算哪个角落被击中。 然后,我会交换x和y的运动。 对于需要的两个角球,对于后两个角球我必须将其中的一个倒置,这取决于球的角落和方向。 最后: private void reflectCorner(Rectangle rect) { double temp = this.dx; this.dx = this.dy; this.dy = temp; temp = 0; ...
  • 检测圆和矩形的碰撞是非常简单的。 这是一个C ++示例类 ,它可以完成这种测试( 源代码有很多其他的相交测试示例 )。 SO上也有一个答案 ,只显示伪代码。 N +开发人员还解释了他们的圆与矩形碰撞检测的方法 。 如果这对你来说似乎太多了,那么你在这里建议寻找一个更简单的方法。 ;) 例如,因为你提到了“箭头”,这意味着一个尖的细的物体倾向于在一个方向上相对直线飞行,箭头总是指向飞行方向。 如果情况并非如此,我可能一直生活在一个不同的星球上,否则我会用这个假设。 这意味着您可以非常轻松地将箭头的碰撞类型从矩 ...
  • 如果要按图像填充矩形,可以按照以下步骤操作: - 在fxml文件中添加一个圆 在您的控制器中 @FXML private Rectangle rectangle; Image img = new Image("/image/rifat.jpg"); rectangle.setFill(new ImagePattern(img)); if you want to fill Rectangle by image, you can follo ...
  • BorderPane管理其组件的布局,因此它通过设置layoutX和layoutY属性为您定位圆圈,使其显示在左上角。 将其包裹在不执行布局的Pane中,并将Pane放在边框窗格的顶部: borderPane.setTop(new Pane(circle)); 请注意,您已设置好所有内容,使其最初处于屏幕外。 您可能想要增加场景的大小: Scene scene = new Scene(borderPane, 600, 600); A BorderPane manages the layout of it ...
  • 您添加的最后一个圆圈显示在矩形的顶部; 但矩形显示在所有其他圆圈的顶部。 因此,只有添加的最后一个圆圈才能获得鼠标点击(其他圆圈的点击定位到矩形)。 最快的解决方法是使矩形鼠标透明: boundingRect.setMouseTransparent(true); 整体上更好的解决方案可能只是创建一个矩形并更新其x , y , width和height属性。 这样你就可以确保矩形被添加一次并保持在堆栈的底部。 The last circle you add appears on top of the rec ...
  • 我实际上忘了给这个答案,所以这里是: public void start(Stage primaryStage) throws Exception { // Choose a Object to move around the Path Circle objectCircle = new Circle(); objectCircle.setRadius(10); // Use a Shape for the Path or... Circle pat ...
  • 尝试使用getBoundsInParent()而不是getBoundsInLocal() 。 一些快速测试表明,当使用local时, BoundingBox在两个不同的位置之间没有变化,但在使用in-parent时却没有。 我猜这是因为getBoundsInParent()使用节点上的变换(有关更多信息,请参阅两者之间的Javadoc)。 但是,我没有测试这是否会影响交叉方法的结果。 编辑:决定做更多的测试。 将两个Rectangle添加到StackPane并移动一个,表明“local” 始终显示为true ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)