无法使用工厂方法模式控制实例?(Cannot control instances with factory method pattern?)
工厂的一个好处是它不一定要返回一个新对象。 它可以改为从对象池返回对象。
这很好,但为了让工厂在需要时创建一个对象,这些对象类需要公共构造函数。 因此,理论上有人可以直接上课并要求新的实例,工厂也不知道。 在工厂外创建的对象不会添加到对象池中。
有没有办法阻止在工厂外创建对象?
One of the benefits of a factory is that it doesn't necessarily have to return a new object. It can instead return objects from an object pool.
This is great, but in order for the factory to create an object when it needs to, those object classes need public constructors. Therefore somebody could theoretically go straight to the class and ask for a new instance and the factory would have no idea. The object that was created outside the factory would not be added to the object pool.
Is there any way to stop objects from being created outside the factory?
原文:https://stackoverflow.com/questions/7052548
最满意答案
您正在使用
Button
组件而不导入它:<Button bsStyle="success" type="submit">Submit</Button>
正确导入并解决问题。
You are using the
Button
component without importing it:<Button bsStyle="success" type="submit">Submit</Button>
Import it correctly and the issue should be resolved.
相关问答
更多-
很可能您的Layout文件不会从此行导出其中一个变量 import { Grid, Row, Column, List, ListItem } from '../../components/Layout'; 如果其中一个未定义,则会发生警告。 It is likely that your Layout file is not exporting one of the variables from this line import { Grid, Row, Column, List, ListItem } ...
-
你需要导入Router等 var Router = require('react-router').Router You need to import Router such as var Router = require('react-router').Router
-
这是由于您的Navbar.Header和您在Navbar使用的任何其他项目未定义的原因,但您的Navbar.Header已定义。 这可能是由于你的宝贝没有正确解决它们的原因 尝试使用不同的导入方式 import React from 'react'; import ReactDOM from 'react-dom'; import {Navbar, Nav, NavItem, NavDropdown, Button, Jumbotron, MenuItem} from 'react-bootstrap'; ...
-
您不从app.jsx导出Test 。 这意味着它不能作为导入使用,因此undefined 。 根据您当前的代码,您需要添加: export default Test; 到app.jsx 。 You don't export Test from app.jsx. This means it's not available as an import, thus the undefined. Based on your current code you'd need to add: export default ...
-
您正在使用Button组件而不导入它: 正确导入并解决问题。 You are using the Button component without importing it: Import it correctly and the issue should be resolved.
-
ConnectedRouter组件可用于react-router-redux版本5.请看这个问题 。 正如我们从您的依赖项中可以看到的,您当前使用的是react-router-redux版本4。 所以你应该用这种方式升级你的react-router-redux包: 如果你使用npm : npm install react-router-redux@next 或者如果你使用yarn : yarn add react-router-redux@next ConnectedRouter component a ...
-
您的反应版本是否与您的react-bootstrap版本或引导NAV设施兼容? 根据这个 ,可能版本会导致错误。 或者你检查了反应路由器,因为你正在使用Link property.did你检查这个 ? Is your react version compatible with your react-bootstrap version, or bootstrap NAV facilities? according to this, maybe versions cause the error. Or did ...
-
React.createElement:type不应为null或undefined(React.createElement: type should not be null or undefined)[2022-09-18]
最后我想出了react-router不推荐使用的方法引起的问题。 在react-router 2.0使用Router和history的正确方法是: import {Router, browserHistory} from "react-router"; ... ReactDOM.render( , document.querySe ...{router} -
好的,这是一个愚蠢的。 我只是错误地导入ReduxRouter。 正确导入是: import { ReduxRouter } from 'redux-router' 感谢Reactiflux的@tomo指出了这一点! OK, that was a stupid one. I was just importing ReduxRouter incorrectly. Correct import is : import { ReduxRouter } from 'redux-router' Thanks to ...
-
我“建议”的是因为我无法从你的代码中做更多的事情: 1)您得到的错误是因为您没有正确调用React.createElement 。 你应该用简单的段来编写你的代码,我建议把它分成三部分,定义,创建和渲染...... // define your element var definitionObject = { // a property called render which is a function which returns your markup. render: function() { ...