ECE 449 OOP and Computer Simulation Lecture 11 Design Patterns
|
|
- Norma Gibson
- 6 years ago
- Views:
Transcription
1 ECE 449 Object-Oriented Programming and Computer Simulation, Fall 2017, Dept. of ECE, IIT 1/60 ECE 449 OOP and Computer Simulation Lecture 11 Design Patterns Professor Jia Wang Department of Electrical and Computer Engineering Illinois Institute of Technology November 3, 2017
2 ECE 449 Object-Oriented Programming and Computer Simulation, Fall 2017, Dept. of ECE, IIT 2/60 Outline Builder Prototype Singleton Composite Factory Factory Methods Abstract Factory
3 ECE 449 Object-Oriented Programming and Computer Simulation, Fall 2017, Dept. of ECE, IIT 3/60 Reading Assignment This lecture: None Next lecture: 14
4 ECE 449 Object-Oriented Programming and Computer Simulation, Fall 2017, Dept. of ECE, IIT 4/60 Outline Builder Prototype Singleton Composite Factory Factory Methods Abstract Factory
5 ECE 449 Object-Oriented Programming and Computer Simulation, Fall 2017, Dept. of ECE, IIT 5/60 The Design Problem bool netlist::create(const evl_wires &wires, const evl_components &comps ); bool netlist::create_nets(const evl_wires &wires); bool netlist::create_gates(const evl_components &comps ); bool netlist::create_gate(const evl_component &c ); bool gate::create(const evl_component &c ); bool gate::create_pin(const evl_pin &p ); bool pin::create( const evl_pin &p ); There are two groups of objects participating in the creation of the netlist. The specification of the netlist: evl_xxxx The netlist data structure: netlist/gate/pin The creation of the netlist is closely coupled to EasyVL. What if we need to change either group of the objects? To adopt a new data structure? To support a new hardware description language? Can we design the classes in a way so the other group can remain unchanged?
6 ECE 449 Object-Oriented Programming and Computer Simulation, Fall 2017, Dept. of ECE, IIT 6/60 The Builder Pattern A creational pattern Separate the construction of a complex object (the EasyVL specification) from its representation (the netlist data structure) Builder: an abstract interface for creating the complex object from its parts Director: construct the complex object using the Builder interface
7 ECE 449 Object-Oriented Programming and Computer Simulation, Fall 2017, Dept. of ECE, IIT 7/60 The Builder Interface struct netlist_builder_i { virtual void add_net(std::string name) = 0; // return the ID# of the gate virtual size_t add_gate(std::string type, std::string name) = 0; // create a pin and append it to a gate virtual void gate_append_pin(size_t gate_id, std::string bus_name, int lsb, int msb) = 0; ; // struct netlist_builder_i Assume errors are handled through exceptions. An abstract interface without any implementation Define steps to construct the complex object from its parts independent of the specification How the complex object is constructed, is not specified. Even the classes for the complex object and the parts are not defined leaving great flexibility. In other words, only the responsibility itself is specified.
8 ECE 449 Object-Oriented Programming and Computer Simulation, Fall 2017, Dept. of ECE, IIT 7/60 The Builder Interface struct netlist_builder_i { virtual void add_net(std::string name) = 0; // return the ID# of the gate virtual size_t add_gate(std::string type, std::string name) = 0; // create a pin and append it to a gate virtual void gate_append_pin(size_t gate_id, std::string bus_name, int lsb, int msb) = 0; ; // struct netlist_builder_i Assume errors are handled through exceptions. An abstract interface without any implementation Define steps to construct the complex object from its parts independent of the specification How the complex object is constructed, is not specified. Even the classes for the complex object and the parts are not defined leaving great flexibility. In other words, only the responsibility itself is specified.
9 ECE 449 Object-Oriented Programming and Computer Simulation, Fall 2017, Dept. of ECE, IIT 7/60 The Builder Interface struct netlist_builder_i { virtual void add_net(std::string name) = 0; // return the ID# of the gate virtual size_t add_gate(std::string type, std::string name) = 0; // create a pin and append it to a gate virtual void gate_append_pin(size_t gate_id, std::string bus_name, int lsb, int msb) = 0; ; // struct netlist_builder_i Assume errors are handled through exceptions. An abstract interface without any implementation Define steps to construct the complex object from its parts independent of the specification How the complex object is constructed, is not specified. Even the classes for the complex object and the parts are not defined leaving great flexibility. In other words, only the responsibility itself is specified.
10 ECE 449 Object-Oriented Programming and Computer Simulation, Fall 2017, Dept. of ECE, IIT 7/60 The Builder Interface struct netlist_builder_i { virtual void add_net(std::string name) = 0; // return the ID# of the gate virtual size_t add_gate(std::string type, std::string name) = 0; // create a pin and append it to a gate virtual void gate_append_pin(size_t gate_id, std::string bus_name, int lsb, int msb) = 0; ; // struct netlist_builder_i Assume errors are handled through exceptions. An abstract interface without any implementation Define steps to construct the complex object from its parts independent of the specification How the complex object is constructed, is not specified. Even the classes for the complex object and the parts are not defined leaving great flexibility. In other words, only the responsibility itself is specified.
11 ECE 449 Object-Oriented Programming and Computer Simulation, Fall 2017, Dept. of ECE, IIT 8/60 The Director Implementation void evl_director(netlist_builder_i *builder, const evl_wires &wires, const evl_components &comps) { for each wire w in wires { for each net w[i] in w { builder->add_net(w[i]); create wires_table for each component c in comps { id = builder->add_gate(c.type, c.name); for each pin p in c.pins { resolve semantics of p using wires_table builder->gate_append_pin(id, p.name, p.lsb, p.msb); The director follows the specification to build the complex object through the builder interface. Without any knowledge of the complex object Program for the interface but not the implementation This is the first time we specify an interface without provide any implementation, while still being able to write a program.
12 Implement a Builder class netlist_builder : public netlist_builder_i { netlist_builder(const netlist_builder &); // no copy netlist_builder &operator=(const netlist_builder &); // no assignment netlist &nl_; // the netlist to be built void add_net(std::string name); size_t add_gate(std::string type, std::string name); void gate_append_pin(size_t gate_id, std::string bus_name, int lsb, int msb); public: netlist_builder(netlist &nl) : nl_(nl) { bool finalize_creation(); ; // class netlist_builder To implement the builder, we need to implement the pure virtual functions in a derived class and prepare classes for the complex object and its parts. Assume netlist_builder is friend of netlist, gate, etc., and thus can access their private members. Additional creation steps can be handled by finalize_creation. ECE 449 Object-Oriented Programming and Computer Simulation, Fall 2017, Dept. of ECE, IIT 9/60
13 Implement netlist builder void netlist_builder::add_net(std::string name) { assert(nl_.nets_table_.find(name) == nl_.nets_table_.end()); // append net and update nets_table size_t netlist_builder::add_gate(std::string type, std::string name) { if (type == "evl_dff") { nl_.gates_.push_back(new flip_flop(name)); else if (type == "and") { nl_.gates_.push_back(new and_gate(name)); return nl_.gates_.size()-1; void netlist_builder::gate_append_pin(int gate_id ) { assert(gate_id < nl_.gates_.size()); // append pin to gates_[gate_id] and make connections to nets bool netlist_builder::finalize_creation() { for each gate g in nl_.gates_ { if (!g.validate_structural_semantics()) return false; return true; ECE 449 Object-Oriented Programming and Computer Simulation, Fall 2017, Dept. of ECE, IIT 10/60
14 ECE 449 Object-Oriented Programming and Computer Simulation, Fall 2017, Dept. of ECE, IIT 11/60 Put Everything Together int main(int argc, char *argv[]) { // validate arguments evl_wires wires; evl_components comps; parse_evl_file(argv[1], wires, comps); netlist nl; netlist_builder builder(nl); evl_director(&builder, wires, comps); builder.finalize_creation(); std::string nl_file = std::string(argv[1])+".netlist"; nl.save(nl_file); // save the netlist for Project 3 nl.simulate(1000); // simulate 1000 cycles for Project 4 return 0;
15 ECE 449 Object-Oriented Programming and Computer Simulation, Fall 2017, Dept. of ECE, IIT 12/60 Summary of Participants of the Builder Pattern Builder (netlist_builder_i) Specifies an abstract interface for creating a complex object from its parts ConcreteBuilder (netlist_builder) Constructs and assembles parts of the product object by implementing the Builder interface Provides means for retrieving the product object and/or finalizing the creation Director (evl_director) Constructs a complex object using the Builder interface Can be a class to handle more complicated creation process Product (netlist, gate, etc.) Represent the complex object under construction Details are revealed to and only to ConcreteBuilder for creation.
16 ECE 449 Object-Oriented Programming and Computer Simulation, Fall 2017, Dept. of ECE, IIT 13/60 Benefits of the Builder Pattern It lets you vary a product s internal representation. The internal representation of the product, i.e. the product types, together with the method to assemble it, is hidden from the director. All you have to do to change the product s internal representation is to define a new kind of ConcreteBuilder. It isolates code for construction and representation. Code for creation from the specification is centralized in Director. Product types are no longer responsible for creation it s now the responsibility of ConcreteBuilder. Director and ConcreteBuilder can change independently. It gives you finer control over the construction process. The product is constructed step by step under the director s control.
17 ECE 449 Object-Oriented Programming and Computer Simulation, Fall 2017, Dept. of ECE, IIT 14/60 Outline Builder Prototype Singleton Composite Factory Factory Methods Abstract Factory
18 ECE 449 Object-Oriented Programming and Computer Simulation, Fall 2017, Dept. of ECE, IIT 15/60 The Design Problem size_t netlist_builder::add_gate(std::string type, std::string name) { if (type == "evl_dff") { nl_.gates_.push_back(new flip_flop(name)); else if (type == "and") { nl_.gates_.push_back(new and_gate(name)); return nl_.gates_.size()-1; You have to modify this function for any new type of gates. netlist_builder knows too much about the gate implementations. What if you want your simulator to support other types of gates provided by a third-party at runtime? We need to create an object whose type is only known at runtime (as a string).
19 ECE 449 Object-Oriented Programming and Computer Simulation, Fall 2017, Dept. of ECE, IIT 16/60 The Prototype Pattern A creational pattern Specify the kinds of objects (gate implementations) to create using a prototypical instance, and create new objects by copying this prototype Prototype: declare the interface for cloning itself Client: create objects by cloning the prototype
20 ECE 449 Object-Oriented Programming and Computer Simulation, Fall 2017, Dept. of ECE, IIT 17/60 The Prototype Interface class gate { virtual gate *clone(std::string name) = 0; ; // class gate Since all gate implementations are derived from gate, it works as a common interface of the prototypes. The clone function is supposed to return a clone of the prototype. Let keep it private since only netlist_builder should be able to access it. Conceptually, the clone function should call the copy ctor when constructing the new object. However, for classes derived from gate, we choose to construct a gate without pins given its name, since the pins are handled by the Builder pattern.
21 ECE 449 Object-Oriented Programming and Computer Simulation, Fall 2017, Dept. of ECE, IIT 18/60 Implement a Prototype class flip_flip: public gate { gate *clone(std::string name) { return new flip_flop(name); ; // class flip_flop For this example, we can call the ctor to clone the object. In some sense, the prototype only provides the type information.
22 ECE 449 Object-Oriented Programming and Computer Simulation, Fall 2017, Dept. of ECE, IIT 19/60 Covariant Return Types class flip_flip: public gate { flip_flop *clone(std::string name) { return new flip_flop(name); ; // class flip_flop It is much more intuitive to let flip_flop::clone to return a flip_flop pointer. C++ allows unmatched function return types for virtual functions as long as they are covariant. The base pointer (or reference) as the function return type in the base class can be changed to the derived pointer (or reference) in the derived class.
23 Prototype Storage typedef std::map<std::string, gate *> gate_prototypes; class flip_flip: public gate { public: static void store_prototype(gate_prototypes &gps) { assert(gps.find("evl_dff") == gps.end()); gps["evl_dff"] = new flip_flop("prototype"); ; // class flip_flop We can store the prototypes in a container. Since we may need to search for a specific prototype by name, an associative container is necessary. By asking each prototype to register for itself, they can have all their ctors and dtors to be private perfect for hiding implementation details. The prototype won t be deleted, but that s not a concern. It should persist throughout the program execution, and the OS will reclaim the heap memory any way at the end. ECE 449 Object-Oriented Programming and Computer Simulation, Fall 2017, Dept. of ECE, IIT 20/60
24 ECE 449 Object-Oriented Programming and Computer Simulation, Fall 2017, Dept. of ECE, IIT 21/60 The Client class netlist_builder : public netlist_builder_i { gate_prototypes &gps_; public: netlist_builder(netlist &nl, gate_prototypes &gps) : nl_(nl), gps_(gps) { ; // class netlist_builder size_t netlist_builder::add_gate(std::string type, std::string name) { if (gps_.find(type) == gps_.end()) ; // handling errors nl_.gates_.push_back(gps_[type]->clone(name)); return nl_.gates_.size()-1; netlist_builder knows nothing about the gate implementations. A corresponding clone function will be called to generate a object as specified by the string type.
25 Put Everything Together void store_standard_gate_prototypes(gate_prototypes &gps) { flip_flop::store_prototype(gps); and_gate::store_prototype(gps); int main(int argc, char *argv[]) { // validate arguments and prepare wires and comps gate_prototypes gps; store_standard_gate_prototypes(gps); store_third_party_prototypes(gps); netlist nl; netlist_builder builder(nl, gps); evl_director(&builder, wires, comps); builder.finalize_creation(); // save the netlist nl or perform simulation The use of the Builder pattern enables us to modify netlist_builder without affecting evl_director and the netlist constructed in main. ECE 449 Object-Oriented Programming and Computer Simulation, Fall 2017, Dept. of ECE, IIT 22/60
26 ECE 449 Object-Oriented Programming and Computer Simulation, Fall 2017, Dept. of ECE, IIT 23/60 Summary of Participants of the Prototype Pattern Prototype (gate) Declare an interface for cloning itself ConcretePrototype (flip_flop, and_gate, etc) Implement an operation for cloning itself Client (netlist_builder::add_gate) Create a new object by asking a prototype to clone itself
27 ECE 449 Object-Oriented Programming and Computer Simulation, Fall 2017, Dept. of ECE, IIT 23/60 Summary of Participants of the Prototype Pattern Prototype (gate) Declare an interface for cloning itself ConcretePrototype (flip_flop, and_gate, etc) Implement an operation for cloning itself Client (netlist_builder::add_gate) Create a new object by asking a prototype to clone itself
28 ECE 449 Object-Oriented Programming and Computer Simulation, Fall 2017, Dept. of ECE, IIT 23/60 Summary of Participants of the Prototype Pattern Prototype (gate) Declare an interface for cloning itself ConcretePrototype (flip_flop, and_gate, etc) Implement an operation for cloning itself Client (netlist_builder::add_gate) Create a new object by asking a prototype to clone itself
29 ECE 449 Object-Oriented Programming and Computer Simulation, Fall 2017, Dept. of ECE, IIT 24/60 Benefits of the Prototype Pattern Hide concrete product classes from the client Greatly reduce the number of names the client know about less coupling Add and remove products at runtime, or even configure an application with classes dynamically Specify new types of objects by varying values or structure without introducing new class types In the bonus project, can you create prototypes for different types of modules? Reduce the necessity of inheritance for other creational patterns In our original netlist_builder design, introducing a new gate type without modifying it would require to derive a new ConcreteBuilder from it.
30 ECE 449 Object-Oriented Programming and Computer Simulation, Fall 2017, Dept. of ECE, IIT 25/60 Outline Builder Prototype Singleton Composite Factory Factory Methods Abstract Factory
31 ECE 449 Object-Oriented Programming and Computer Simulation, Fall 2017, Dept. of ECE, IIT 26/60 The Design Problem void store_standard_gate_prototypes(gate_prototypes &gps); void store_third_party_prototypes(gate_prototypes &gps); netlist_builder::netlist_builder(netlist &nl, gate_prototypes &gps); void flip_flip::store_prototype(gate_prototypes &gps); void and_gate::store_prototype(gate_prototypes &gps); When calling these functions, all the parameters gps should refer to the same gate_prototypes object. How to enforce the requirement? People familiar with C may propose to use a global variable gps. However, there is no guarantee all these functions will use that gps object.
32 ECE 449 Object-Oriented Programming and Computer Simulation, Fall 2017, Dept. of ECE, IIT 27/60 The Singleton Pattern A creational pattern Ensure a class only has one instance, and provide a global point of access to it Unlike previous patterns, the Singleton pattern won t rely on polymorphism.
33 ECE 449 Object-Oriented Programming and Computer Simulation, Fall 2017, Dept. of ECE, IIT 28/60 The Singleton Interface // gate_prototypes.h class gate_prototypes { gate_prototypes(const gate_prototypes &) = delete; gate_prototypes &operator=(const gate_prototypes &) = delete; gate_prototypes() { ~gate_prototypes() { // use private ctor and dtor to prevent // the creation of additional instances std::map<std::string, gate *> prototypes_; public: void store(std::string name, gate *g); gate *locate(std::string name); static gate_prototypes &instance(); // access the only instance ; // class gate_prototypes Use static member function to provide access to the only class instance.
34 ECE 449 Object-Oriented Programming and Computer Simulation, Fall 2017, Dept. of ECE, IIT 29/60 The Singleton Implementation // gate_prototypes.cpp gate_prototypes &gate_prototypes::instance() { static gate_prototypes instance; // the only instance return instance; static variable in a function is constructed the first time when the function is called. Will persist throughout the program execution. Most importantly, the C++ runtime guarantees that the variable is constructed exactly once even in a multi-threading environment. A static member function can access all private members.
35 ECE 449 Object-Oriented Programming and Computer Simulation, Fall 2017, Dept. of ECE, IIT 30/60 Use Singleton // netlist_builder.h class netlist_builder : public netlist_builder_i { public: netlist_builder(netlist &nl) : nl_(nl) { ; // class netlist_builder // netlist_builder.cpp #include "gate_prototypes.h" size_t netlist_builder::add_gate(std::string type, std::string name) { gate *prototype = gate_prototypes::instance().locate(type); if (prototype == NULL) ; // handling errors nl_.gates_.push_back(prototype->clone(name)); return nl_.gates_.size()-1; To access the only instance, one just need to make sure the Singleton class type is available.
36 ECE 449 Object-Oriented Programming and Computer Simulation, Fall 2017, Dept. of ECE, IIT 31/60 Use Singleton: Another Example // gate_implementations.h class flip_flip: public gate { public: static void store_prototype(); ; // class flip_flop void store_standard_gate_prototypes(); // gate_implementations.cpp #include "gate_prototypes.h" void flip_flip::store_prototype() { gate_prototypes::instance().store("evl_dff", new flip_flop("prototype")); void store_standard_gate_prototypes() { flip_flop::store_prototype(); and_gate::store_prototype();
37 ECE 449 Object-Oriented Programming and Computer Simulation, Fall 2017, Dept. of ECE, IIT 32/60 Put Everything Together int main(int argc, char *argv[]) { // validate arguments and prepare wires and comps store_standard_gate_prototypes(); store_third_party_prototypes(); netlist nl; netlist_builder builder(nl); evl_director(&builder, wires, comps); builder.finalize_creation(); // save the netlist nl or perform simulation The prototype storage is completely hidden.
38 ECE 449 Object-Oriented Programming and Computer Simulation, Fall 2017, Dept. of ECE, IIT 33/60 Benefits of the Singleton Pattern Controlled access to sole instance The compiler will enforce the controlled access via protections. Reduced name space A global variable would provide global access but will pollute the global name space since you have to name it. The singleton, on the other hand, simply requires a type. Permit refinement of operations and representation Since accesses are centralized, it is easy to refine/replace the singleton with an updated implementation. Permit a variable number of instances You may extend the pattern to provide more instances and controlled accesses to them.
39 ECE 449 Object-Oriented Programming and Computer Simulation, Fall 2017, Dept. of ECE, IIT 34/60 Outline Builder Prototype Singleton Composite Factory Factory Methods Abstract Factory
40 ECE 449 Object-Oriented Programming and Computer Simulation, Fall 2017, Dept. of ECE, IIT 35/60 The Design Problem Our netlist is consisting of nets and predefined gates. What if we allow the hardware designer to specify their own types of gates, i.e. modules? These modules can then be reused to construct larger modules, eventually become a very complicated system. Usually known as the hierarchical design methodology, and is used for any practical hardware design How to represent such hierarchical structure?
41 ECE 449 Object-Oriented Programming and Computer Simulation, Fall 2017, Dept. of ECE, IIT 36/60 The Composite Pattern A structural pattern Compose objects into tree structures to represent part-whole hierarchies. Composite lets clients treat individual objects and compositions of objects uniformly. Component: the interface of objects in the composition Leaf: primitive objects in the composition Composite: objects constructed from leaves and composites
42 ECE 449 Object-Oriented Programming and Computer Simulation, Fall 2017, Dept. of ECE, IIT 37/60 The Component Interface class gate { ; // class gate Since conceptually a netlist is consisting of nets and gates, it is intuitive to use gate as the common interface to the objects in the hierarchy. The gate class allows to access behavior of derived classes through virtual functions.
43 ECE 449 Object-Oriented Programming and Computer Simulation, Fall 2017, Dept. of ECE, IIT 38/60 The Leaves class flip_flop: public gate { ; // class flip_flop class and_gate: public gate { ; // class and_gate The primitive objects are the predefined gates in our design. Leaves are defined using public inheritance.
44 ECE 449 Object-Oriented Programming and Computer Simulation, Fall 2017, Dept. of ECE, IIT 39/60 The Composite class module: public gate { public: module(std::string type, std::string name) : gate(type, name) { ; // class module Since the composite should also be accessed from the component interface, it should be derived from it.
45 ECE 449 Object-Oriented Programming and Computer Simulation, Fall 2017, Dept. of ECE, IIT 40/60 The Composite: Child Components class module: public gate { module *parent_; // optional, will be NULL for top module std::list<gate *> children_; public: module(std::string type, std::string name, module *parent); ; // class module The composite is made up of child components. They could be primitive objects or other composites. There is only one class type for the composite. Different types of composite differ in their child components. As usual, the child components are managed by a container. It is optional for the composite to have a pointer to its parent, initialized when constructing the object.
46 ECE 449 Object-Oriented Programming and Computer Simulation, Fall 2017, Dept. of ECE, IIT 41/60 Updated Composite Implementation class module : public gate { netlist nl_; // internal structure std::vector<port *> ports_; // should match pins_ bool validate_structural_semantics() override; void compute_next_state_or_output() override; char compute_signal(int pin_index) override; module *clone() override; public: module(std::string type, std::string name); ~module(); ; // class module For module, in addition to gates, there are nets. So it is more convenient to use netlist as the container. An additional benefit is we can use a builder to construct nl_.
47 ECE 449 Object-Oriented Programming and Computer Simulation, Fall 2017, Dept. of ECE, IIT 42/60 Issues Is there any cyclic type dependency between module and netlist? No. Because the type netlist only depends on the type gate. However, the whole system should be a tree this should be verified and guaranteed when constructing the system. How to construct the whole system?
48 ECE 449 Object-Oriented Programming and Computer Simulation, Fall 2017, Dept. of ECE, IIT 43/60 Summary of Participants of the Composite Pattern Component (gate) Declare the interface for objects in the composition Implement default behavior for the interface common to all classes, as appropriate Optionally, it may declare interfaces for accessing and managing its child components, and accessing its parent. Leaf (flip_flop, add_gate, etc.) Represent leaf objects in the composition, which have no children Define behavior for primitive objects in the composition Composite (module) Define behavior for components having children Store child components Implement child-related operations in the Component interface Client: any code that access objects in the composition through the Component interface
49 ECE 449 Object-Oriented Programming and Computer Simulation, Fall 2017, Dept. of ECE, IIT 44/60 Benefits of the Composite Pattern Define class hierarchies consisting of primitive objects and composite objects Primitive objects can be composed into more complex objects, which in turn can be composed, and so on recursively and hierarchically. Wherever client code expects a primitive object, it may also take a composite object. Make the client simple Clients can treat composite structures and individual objects uniformly. Clients normally don t know (and shouldn t care) whether they re dealing with a leaf or a composite component this forces programmers to write code for the interface instead of for the implementation. Make it easier to add new kinds of components
50 ECE 449 Object-Oriented Programming and Computer Simulation, Fall 2017, Dept. of ECE, IIT 45/60 Outline Builder Prototype Singleton Composite Factory Factory Methods Abstract Factory
51 ECE 449 Object-Oriented Programming and Computer Simulation, Fall 2017, Dept. of ECE, IIT 46/60 The Design Problem size_t netlist_builder::add_gate(std::string type, std::string name) { gate *prototype = gate_prototypes::instance().locate(type); if (prototype == NULL) ; // handling errors nl_.gates_.push_back(prototype->clone(name)); return nl_.gates_.size()-1; void netlist_builder::add_net(std::string name) { nl_.nets_.push_back(new net); void netlist_builder::gate_append_pin(int gate_id ) { nl_.gates_[gate_id]->pins_.push_back(new pin); What if we want to bypass the prototypes for specific gate types? What if we want to replace net/pin with other types? Can we extend how parts are created but reuse the code for assembling them?
52 ECE 449 Object-Oriented Programming and Computer Simulation, Fall 2017, Dept. of ECE, IIT 47/60 The Factory Patterns Two creational patterns that are closely related Define an interface to create objects, usually parts of a complex object Factory Methods The process to construct a complex object actually follows an algorithm. Therefore, we can apply the Template Method pattern to define parts creation as primitive operations. To emphasize that such primitive operations do create objects, we call them factory methods. Abstract Factory Alternatively, it is also possible to follow the Builder pattern to separate the parts creation from parts assembling by using an abstract interface.
53 ECE 449 Object-Oriented Programming and Computer Simulation, Fall 2017, Dept. of ECE, IIT 48/60 Outline Builder Prototype Singleton Composite Factory Factory Methods Abstract Factory
54 ECE 449 Object-Oriented Programming and Computer Simulation, Fall 2017, Dept. of ECE, IIT 49/60 The Factory Methods class netlist_builder : public netlist_builder_i { virtual gate *make_gate(std::string type, std::string name); virtual net *make_net(); virtual pin *make_pin(); ; // class netlist_builder gate *netlist_builder::make_gate(std::string type, std::string name) { gate *prototype = gate_prototypes::instance().locate(type); if (prototype == NULL) ; // handling errors return prototype->clone(name); net *netlist_builder::make_net() {return new net; pin *netlist_builder::make_pin() {return new pin; The factory methods are only responsible for parts creation but not parts assembling.
55 ECE 449 Object-Oriented Programming and Computer Simulation, Fall 2017, Dept. of ECE, IIT 50/60 Products class netlist_builder : public netlist_builder_i { virtual gate *make_gate(std::string type, std::string name); virtual net *make_net(); virtual pin *make_pin(); ; // class netlist_builder gate serves as an interface to the products created by the factory method make_gate. For this example, net/pin serve as both the interfaces and the implementations of the products. To use new product classes, They should be derived from the corresponding product interfaces. Derive a new class from netlist_builder and override only the factory methods (make_xxxx)
56 ECE 449 Object-Oriented Programming and Computer Simulation, Fall 2017, Dept. of ECE, IIT 51/60 Use Factory Methods in Builder size_t netlist_builder::add_gate(std::string type, std::string name) { nl_.gates_.push_back(make_gate(type, name)); void netlist_builder::add_net(std::string name) { nl_.nets_.push_back(make_net()); void netlist_builder::gate_append_pin(int gate_id ) { nl_.gates_[gate_id]->pins_.push_back(make_pin()); Follow the Template Method pattern to implement the algorithms using primitive operations, which are the factory methods
57 ECE 449 Object-Oriented Programming and Computer Simulation, Fall 2017, Dept. of ECE, IIT 52/60 Summary of Participants of the Factory Method Pattern Product (gate, net, pin) Interfaces to parts, which are created by factory methods ConcreteProduct (flip_flop, net, pin, etc) Implements the Product interface Creator (netlist_builder) Declare the factory methods that return objects accessed from Product interfaces Provide default implementations of the factory methods if necessary Call factory methods to create objects ConcreteCreator Override the factory methods to return instances of ConcreteProduct types.
58 ECE 449 Object-Oriented Programming and Computer Simulation, Fall 2017, Dept. of ECE, IIT 53/60 Outline Builder Prototype Singleton Composite Factory Factory Methods Abstract Factory
59 ECE 449 Object-Oriented Programming and Computer Simulation, Fall 2017, Dept. of ECE, IIT 54/60 The Factory Interface struct netlist_factory_i { virtual gate *make_gate(std::string type, std::string name) = 0; virtual net *make_net() = 0; virtual pin *make_pin() = 0; ; // struct netlist_factory_i Abstract factory is an abstract interface defining how parts are created. It returns products through Product interfaces.
60 size_t netlist_builder::add_gate(std::string type, std::string name) { nl_.gates_.push_back(factory_->make_gate(type, name)); void netlist_builder::add_net(std::string name) { nl_.nets_[name] = factory_->make_net(); void netlist_builder::gate_append_pin(int gate_id ) { nl_.gates_[gate_id]->pins_.push_back(factory_->make_pin()); Parts creations in the client (netlist_builder) are ECE 449 Object-Oriented Programming and Computer Simulation, Fall 2017, Dept. of ECE, IIT 55/60 The Client class netlist_builder : public netlist_builder_i { netlist_factory_i *factory_; public: netlist_builder(netlist &nl, netlist_factory_i *factory) : nl_(nl), factory_(factory) { ; // class netlist_builder
61 ECE 449 Object-Oriented Programming and Computer Simulation, Fall 2017, Dept. of ECE, IIT 56/60 Implement a Factory class netlist_factory : public netlist_factory_i { virtual gate *make_gate(std::string type, std::string name); virtual net *make_net(); virtual pin *make_pin(); ; // class netlist_factory gate *netlist_factory::make_gate(std::string type, std::string name) { gate *prototype = gate_prototypes::instance()->locate(type); if (prototype == NULL) ; // handling errors return prototype->clone(name); net *netlist_factory::make_net() {return new net; pin *netlist_factory::make_pin() {return new pin; Similar to Builder, a ConcreteFactory is derived from the abstract interface and the pure virtual functions are implemented.
62 ECE 449 Object-Oriented Programming and Computer Simulation, Fall 2017, Dept. of ECE, IIT 57/60 Put Everything Together using Abstract Factory int main(int argc, char *argv[]) { // validate arguments and prepare wires and comps store_standard_gate_prototypes(); store_third_party_prototypes(); netlist nl; netlist_factory factory; netlist_builder builder(nl, &factory); evl_director(&builder, wires, comps); builder.finalize_creation(); // save the netlist nl or perform simulation Can you design a new factory hier_factory to make module objects for hierarchical designs?
63 ECE 449 Object-Oriented Programming and Computer Simulation, Fall 2017, Dept. of ECE, IIT 58/60 A Factory for Hierarchical Design gate *hier_factory::make_gate(std::string type, std::string name) { gate *prototype = gate_prototypes::instance().locate(type); if (prototype!= NULL) return prototype->clone(name); find ports, wires, and comps for the module type // create a module with type type and name name module *p = new module(type, name); p->create_ports(ports); // create the internal netlist using builder and factory netlist_builder builder(p->nl_, this); evl_director(&builder, wires, comps); builder.finalize_creation(); return p; By reusing the factory to build internal netlist, the hierarchical design is created recursively.
64 ECE 449 Object-Oriented Programming and Computer Simulation, Fall 2017, Dept. of ECE, IIT 59/60 Summary of Participants of the Abstract Factory Pattern Factory (or Abstract Factory, netlist_factory_i) Declare an interface for operations that create product objects ConcreteFactory (netlist_factory) Implement the operations to create concrete product objects Product (or AbstractProduct, gate, net, etc.) Declare an interface for a kind of product object ConcreteProduct (flip_flop, net, etc.) Define a product object to be created by the corresponding concrete factory Implement the Product interface Client (netlist_builder) Use only interfaces declared by Factory and Product classes
65 ECE 449 Object-Oriented Programming and Computer Simulation, Fall 2017, Dept. of ECE, IIT 60/60 Summary and Advice Behavioral pattern: Template Method Define the skeleton of an algorithm in an operation, deferring some steps to subclasses A fundamental technique for code reuse in class libraries Creational pattern: Singleton Ensure a class only has one instance, and provide a global point of access to it Additional creational patterns Factory: separate parts creation from parts assembling Builder: separate system specification from system creation Prototypes: hide part types for parts creation Structural pattern: Composite Compose objects into tree structures to represent part-whole hierarchies Component as an interface for leaves and composites
ECE 449 OOP and Computer Simulation Lecture 07 Class Design for Circuit Netlist
ECE 449 Object-Oriented Programming and Computer Simulation, Fall 2017, Dept. of ECE, IIT 1/64 ECE 449 OOP and Computer Simulation Lecture 07 Class Design for Circuit Netlist Professor Jia Wang Department
More informationLaboratorio di Progettazione di Sistemi Software Design Pattern Creazionali. Valentina Presutti (A-L) Riccardo Solmi (M-Z)
Laboratorio di Progettazione di Sistemi Software Design Pattern Creazionali Valentina Presutti (A-L) Riccardo Solmi (M-Z) Indice degli argomenti Catalogo di Design Patterns creazionali: Abstract Factory
More informationSoftware Design COSC 4353/6353 D R. R A J S I N G H
Software Design COSC 4353/6353 D R. R A J S I N G H Creational Design Patterns What are creational design patterns? Types Examples Structure Effects Creational Patterns Design patterns that deal with object
More informationECE 449 OOP and Computer Simulation Lecture 14 Final Exam Review
ECE 449 Object-Oriented Programming and Computer Simulation, Fall 2017, Dept. of ECE, IIT 1/35 ECE 449 OOP and Computer Simulation Lecture 14 Final Exam Review Professor Jia Wang Department of Electrical
More informationCreational Patterns. Factory Method (FM) Abstract Factory (AF) Singleton (SI) Prototype (PR) Builder (BU)
Creational Patterns Creational Patterns Factory Method (FM) Abstract Factory (AF) Singleton (SI) Prototype (PR) Builder (BU) Factory Method (FM) Intent: Define an interface for creating an object, but
More informationECE 449 OOP and Computer Simulation Lecture 12 Resource Management II
ECE 449 Object-Oriented Programming and Computer Simulation, Fall 2017, Dept. of ECE, IIT 1/62 ECE 449 OOP and Computer Simulation Lecture 12 Resource Management II Professor Jia Wang Department of Electrical
More informationDesign Pattern- Creational pattern 2015
Creational Patterns Abstracts instantiation process Makes system independent of how its objects are created composed represented Encapsulates knowledge about which concrete classes the system uses Hides
More informationDesign Patterns. Manuel Mastrofini. Systems Engineering and Web Services. University of Rome Tor Vergata June 2011
Design Patterns Lecture 1 Manuel Mastrofini Systems Engineering and Web Services University of Rome Tor Vergata June 2011 Definition A pattern is a reusable solution to a commonly occurring problem within
More informationECE 449 OOP and Computer Simulation Lecture 09 Logic Simulation
ECE 449 Object-Oriented Programming and Computer Simulation, Fall 2017, Dept. of ECE, IIT 1/31 ECE 449 OOP and Computer Simulation Lecture 09 Logic Simulation Professor Jia Wang Department of Electrical
More informationThink of drawing/diagramming editors. ECE450 Software Engineering II. The problem. The Composite pattern
Think of drawing/diagramming editors ECE450 Software Engineering II Drawing/diagramming editors let users build complex diagrams out of simple components The user can group components to form larger components......which
More informationObject-Oriented Design
Object-Oriented Design Lecturer: Raman Ramsin Lecture 20: GoF Design Patterns Creational 1 Software Patterns Software Patterns support reuse of software architecture and design. Patterns capture the static
More informationModellistica Medica. Maria Grazia Pia, INFN Genova. Scuola di Specializzazione in Fisica Sanitaria Genova Anno Accademico
Modellistica Medica Maria Grazia Pia INFN Genova Scuola di Specializzazione in Fisica Sanitaria Genova Anno Accademico 2002-2003 Lezione 8 OO modeling Design Patterns Introduction Creational Patterns Software
More informationTopics in Object-Oriented Design Patterns
Software design Topics in Object-Oriented Design Patterns Material mainly from the book Design Patterns by Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides; slides originally by Spiros Mancoridis;
More informationAn Introduction to Patterns
An Introduction to Patterns Robert B. France Colorado State University Robert B. France 1 What is a Pattern? - 1 Work on software development patterns stemmed from work on patterns from building architecture
More informationWhat are the characteristics of Object Oriented programming language?
What are the various elements of OOP? Following are the various elements of OOP:- Class:- A class is a collection of data and the various operations that can be performed on that data. Object- This is
More informationC++ Important Questions with Answers
1. Name the operators that cannot be overloaded. sizeof,.,.*,.->, ::,? 2. What is inheritance? Inheritance is property such that a parent (or super) class passes the characteristics of itself to children
More informationCSCI 253. Overview. The Elements of a Design Pattern. George Blankenship 1. Object Oriented Design: Creational Patterns. George Blankenship
CSCI 253 Object Oriented Design: George Blankenship George Blankenship 1 Singleton Abstract factory Factory Method Prototype Builder Overview Structural Patterns Composite Façade Proxy Flyweight Adapter
More informationSingleton Pattern Creational
Singleton Pattern Creational Intent» Ensure a class has only one instance» Provide a global point of access Motivation Some classes must only have one instance file system, window manager Applicability»
More informationCreational Design Patterns
Creational Design Patterns Creational Design Patterns Structural Design Patterns Behavioral Design Patterns GoF Design Pattern Categories Purpose Creational Structural Behavioral Scope Class Factory Method
More informationObject Oriented Programming. Solved MCQs - Part 2
Object Oriented Programming Solved MCQs - Part 2 Object Oriented Programming Solved MCQs - Part 2 It is possible to declare as a friend A member function A global function A class All of the above What
More informationDesign Patterns Reid Holmes
Material and some slide content from: - Head First Design Patterns Book - GoF Design Patterns Book Design Patterns Reid Holmes GoF design patterns $ %!!!! $ "! # & Pattern vocabulary Shared vocabulary
More informationShort Notes of CS201
#includes: Short Notes of CS201 The #include directive instructs the preprocessor to read and include a file into a source code file. The file name is typically enclosed with < and > if the file is a system
More informationDesign Patterns. Comp2110 Software Design. Department of Computer Science Australian National University. Second Semester
Design Patterns Comp2110 Software Design Department of Computer Science Australian National University Second Semester 2005 1 Design Pattern Space Creational patterns Deal with initializing and configuring
More informationChapter 1: Object-Oriented Programming Using C++
Chapter 1: Object-Oriented Programming Using C++ Objectives Looking ahead in this chapter, we ll consider: Abstract Data Types Encapsulation Inheritance Pointers Polymorphism Data Structures and Algorithms
More information4.1 Introduction Programming preliminaries Constructors Destructors An example... 3
Department of Computer Science Tackling Design Patterns Chapter 4: Factory Method design pattern Copyright c 2016 by Linda Marshall and Vreda Pieterse. All rights reserved. Contents 4.1 Introduction.................................
More informationCS201 - Introduction to Programming Glossary By
CS201 - Introduction to Programming Glossary By #include : The #include directive instructs the preprocessor to read and include a file into a source code file. The file name is typically enclosed with
More informationSingleton, Factory Method, Abstract Factory, Named Constructor. Using one or more base classes to hide details from the client
Idioms & Design Patterns Creational Introduction to Design Patterns Patterns and idioms can be grouped roughly into: Creational Patterns and idioms Singleton, Factory Method, Abstract Factory, Named Constructor
More informationThe Strategy Pattern Design Principle: Design Principle: Design Principle:
Strategy Pattern The Strategy Pattern defines a family of algorithms, encapsulates each one, and makes them interchangeable. Strategy lets the algorithm vary independently from clients that use it. Design
More informationDesign Pattern: Composite
Design Pattern: Composite Intent Compose objects into tree structures to represent part-whole hierarchies. Composite lets clients treat individual objects and compositions of objects uniformly. Motivation
More informationSupporting Class / C++ Lecture Notes
Goal Supporting Class / C++ Lecture Notes You started with an understanding of how to write Java programs. This course is about explaining the path from Java to executing programs. We proceeded in a mostly
More informationCOSC 3351 Software Design. Design Patterns Structural Patterns (I)
COSC 3351 Software Design Design Patterns Structural Patterns (I) Spring 2008 Purpose Creational Structural Behavioral Scope Class Factory Method Adaptor(class) Interpreter Template Method Object Abstract
More informationOBJECT ORIENTED PROGRAMMING USING C++ CSCI Object Oriented Analysis and Design By Manali Torpe
OBJECT ORIENTED PROGRAMMING USING C++ CSCI 5448- Object Oriented Analysis and Design By Manali Torpe Fundamentals of OOP Class Object Encapsulation Abstraction Inheritance Polymorphism Reusability C++
More informationTHOMAS LATOZA SWE 621 FALL 2018 DESIGN PATTERNS
THOMAS LATOZA SWE 621 FALL 2018 DESIGN PATTERNS LOGISTICS HW3 due today HW4 due in two weeks 2 IN CLASS EXERCISE What's a software design problem you've solved from an idea you learned from someone else?
More informationLecture 3. COMP1006/1406 (the Java course) Summer M. Jason Hinek Carleton University
Lecture 3 COMP1006/1406 (the Java course) Summer 2014 M. Jason Hinek Carleton University today s agenda assignments 1 (graded) & 2 3 (available now) & 4 (tomorrow) a quick look back primitive data types
More informationIntro to OOP Visibility/protection levels and constructors Friend, convert constructor, destructor Operator overloading a<=b a.
Intro to OOP - Object and class - The sequence to define and use a class in a program - How/when to use scope resolution operator - How/when to the dot operator - Should be able to write the prototype
More informationECE 449 OOP and Computer Simulation Lecture 08 Resource Management I
ECE 449 Object-Oriented Programming and Computer Simulation, Fall 2017, Dept. of ECE, IIT 1/69 ECE 449 OOP and Computer Simulation Lecture 08 Resource Management I Professor Jia Wang Department of Electrical
More informationCHAPTER 6: CREATIONAL DESIGN PATTERNS
CHAPTER 6: CREATIONAL DESIGN PATTERNS SESSION III: BUILDER, PROTOTYPE, SINGLETON Software Engineering Design: Theory and Practice by Carlos E. Otero Slides copyright 2012 by Carlos E. Otero For non-profit
More informationGoF Design Pattern Categories
GoF Design Pattern Categories Purpose Creational Structural Behavioral Scope Class Factory Method Adapter Interpreter Template Method Object Abstract Factory Builder Prototype Singleton Adapter Bridge
More informationECE 3574: Dynamic Polymorphism using Inheritance
1 ECE 3574: Dynamic Polymorphism using Inheritance Changwoo Min 2 Administrivia Survey on class will be out tonight or tomorrow night Please, let me share your idea to improve the class! 3 Meeting 10:
More informationOOPS Viva Questions. Object is termed as an instance of a class, and it has its own state, behavior and identity.
OOPS Viva Questions 1. What is OOPS? OOPS is abbreviated as Object Oriented Programming system in which programs are considered as a collection of objects. Each object is nothing but an instance of a class.
More informationObject-Oriented Oriented Programming
Object-Oriented Oriented Programming Composite Pattern CSIE Department, NTUT Woei-Kae Chen Catalog of Design patterns Creational patterns Abstract Factory, Builder, Factory Method, Prototype, Singleton
More informationKeywords: Abstract Factory, Singleton, Factory Method, Prototype, Builder, Composite, Flyweight, Decorator.
Comparative Study In Utilization Of Creational And Structural Design Patterns In Solving Design Problems K.Wseem Abrar M.Tech., Student, Dept. of CSE, Amina Institute of Technology, Shamirpet, Hyderabad
More informationJava Object Oriented Design. CSC207 Fall 2014
Java Object Oriented Design CSC207 Fall 2014 Design Problem Design an application where the user can draw different shapes Lines Circles Rectangles Just high level design, don t write any detailed code
More informationTecniche di Progettazione: Design Patterns
Tecniche di Progettazione: Design Patterns GoF: Composite 1 Composite pattern Intent Compose objects into tree structures to represent part-whole hierarchies. Composite lets clients treat individual objects
More informationSDC Design patterns GoF
SDC Design patterns GoF Design Patterns The design pattern concept can be viewed as an abstraction of imitating useful parts of other software products. The design pattern is a description of communicating
More informationChapter 6. Object- Oriented Programming Part II
Chapter 6 Object- Oriented Programming Part II 6: Preview issues surrounding the object creational process the Abstract Factory design pattern private and protected inheritance multiple inheritance comparison
More informationObject-Oriented Oriented Programming Factory Method Pattern Abstract Factory Pattern. CSIE Department, NTUT Woei-Kae Chen
Object-Oriented Oriented Programming Factory Method Pattern Abstract Factory Pattern CSIE Department, NTUT Woei-Kae Chen Factory Method Pattern Factory Method Pattern Creational pattern Factory Method:
More informationDesign of Software Systems (Ontwerp van SoftwareSystemen) Design Patterns Reference. Roel Wuyts
Design of Software Systems (Ontwerp van SoftwareSystemen) Design Patterns Reference 2015-2016 Visitor See lecture on design patterns Design of Software Systems 2 Composite See lecture on design patterns
More informationZhifu Pei CSCI5448 Spring 2011 Prof. Kenneth M. Anderson
Zhifu Pei CSCI5448 Spring 2011 Prof. Kenneth M. Anderson Introduction History, Characteristics of Java language Java Language Basics Data types, Variables, Operators and Expressions Anatomy of a Java Program
More informationCommon Misunderstandings from Exam 1 Material
Common Misunderstandings from Exam 1 Material Kyle Dewey Stack and Heap Allocation with Pointers char c = c ; char* p1 = malloc(sizeof(char)); char** p2 = &p1; Where is c allocated? Where is p1 itself
More informationOOPs Concepts. 1. Data Hiding 2. Encapsulation 3. Abstraction 4. Is-A Relationship 5. Method Signature 6. Polymorphism 7. Constructors 8.
OOPs Concepts 1. Data Hiding 2. Encapsulation 3. Abstraction 4. Is-A Relationship 5. Method Signature 6. Polymorphism 7. Constructors 8. Type Casting Let us discuss them in detail: 1. Data Hiding: Every
More informationWhat is Design Patterns?
Paweł Zajączkowski What is Design Patterns? 1. Design patterns may be said as a set of probable solutions for a particular problem which is tested to work best in certain situations. 2. In other words,
More informationIntroduction to C++ Introduction to C++ Dr Alex Martin 2013 Slide 1
Introduction to C++ Introduction to C++ Dr Alex Martin 2013 Slide 1 Inheritance Consider a new type Square. Following how we declarations for the Rectangle and Circle classes we could declare it as follows:
More informationObject oriented programming. Encapsulation. Polymorphism. Inheritance OOP
OOP Object oriented programming Polymorphism Encapsulation Inheritance OOP Class concepts Classes can contain: Constants Delegates Events Fields Constructors Destructors Properties Methods Nested classes
More informationChapter 11. Categories of languages that support OOP: 1. OOP support is added to an existing language
Categories of languages that support OOP: 1. OOP support is added to an existing language - C++ (also supports procedural and dataoriented programming) - Ada 95 (also supports procedural and dataoriented
More informationA Reconnaissance on Design Patterns
A Reconnaissance on Design Patterns M.Chaithanya Varma Student of computer science engineering, Sree Vidhyanikethan Engineering college, Tirupati, India ABSTRACT: In past decade, design patterns have been
More informationWhat is Design Patterns?
Paweł Zajączkowski What is Design Patterns? 1. Design patterns may be said as a set of probable solutions for a particular problem which is tested to work best in certain situations. 2. In other words,
More informationThe GoF Design Patterns Reference
The GoF Design Patterns Reference Version.0 / 0.0.07 / Printed.0.07 Copyright 0-07 wsdesign. All rights reserved. The GoF Design Patterns Reference ii Table of Contents Preface... viii I. Introduction....
More informationInstantiation of Template class
Class Templates Templates are like advanced macros. They are useful for building new classes that depend on already existing user defined classes or built-in types. Example: stack of int or stack of double
More informationG Programming Languages - Fall 2012
G22.2110-003 Programming Languages - Fall 2012 Lecture 12 Thomas Wies New York University Review Last lecture Modules Outline Classes Encapsulation and Inheritance Initialization and Finalization Dynamic
More informationFast Introduction to Object Oriented Programming and C++
Fast Introduction to Object Oriented Programming and C++ Daniel G. Aliaga Note: a compilation of slides from Jacques de Wet, Ohio State University, Chad Willwerth, and Daniel Aliaga. Outline Programming
More informationSingleton Pattern Creational. » Ensure a class has only one instance» Provide a global point of access
Singleton Pattern Creational Intent» Ensure a class has only one instance» Provide a global point of access Motivation Some classes must only have one instance file system, window manager Applicability»
More informationFINAL TERM EXAMINATION SPRING 2010 CS304- OBJECT ORIENTED PROGRAMMING
FINAL TERM EXAMINATION SPRING 2010 CS304- OBJECT ORIENTED PROGRAMMING Question No: 1 ( Marks: 1 ) - Please choose one Classes like TwoDimensionalShape and ThreeDimensionalShape would normally be concrete,
More informationInformation systems modelling UML and service description languages
Internet Engineering Tomasz Babczyński, Zofia Kruczkiewicz Tomasz Kubik Information systems modelling UML and service description languages Overview of design patterns for supporting information systems
More informationDay 4. COMP1006/1406 Summer M. Jason Hinek Carleton University
Day 4 COMP1006/1406 Summer 2016 M. Jason Hinek Carleton University today s agenda assignments questions about assignment 2 a quick look back constructors signatures and overloading encapsulation / information
More informationC++ Inheritance and Encapsulation
C++ Inheritance and Encapsulation Private and Protected members Inheritance Type Public Inheritance Private Inheritance Protected Inheritance Special method inheritance 1 Private Members Private members
More informationCSE 303: Concepts and Tools for Software Development
CSE 303: Concepts and Tools for Software Development Hal Perkins Autumn 2008 Lecture 24 Introduction to C++ CSE303 Autumn 2008, Lecture 24 1 C++ C++ is an enormous language: All of C Classes and objects
More informationM301: Software Systems & their Development. Unit 4: Inheritance, Composition and Polymorphism
Block 1: Introduction to Java Unit 4: Inheritance, Composition and Polymorphism Aims of the unit: Study and use the Java mechanisms that support reuse, in particular, inheritance and composition; Analyze
More informationObject Oriented Methods with UML. Introduction to Design Patterns- Lecture 8
Object Oriented Methods with UML Introduction to Design Patterns- Lecture 8 Topics(03/05/16) Design Patterns Design Pattern In software engineering, a design pattern is a general repeatable solution to
More informationComputer Systems Assignment 2: Fork and Threads Package
Autumn Term 2018 Distributed Computing Computer Systems Assignment 2: Fork and Threads Package Assigned on: October 5, 2018 Due by: October 12, 2018 1 Understanding fork() and exec() Creating new processes
More informationObject-Oriented Programming, Iouliia Skliarova
Object-Oriented Programming, Iouliia Skliarova CBook a = CBook("C++", 2014); CBook b = CBook("Physics", 1960); a.display(); b.display(); void CBook::Display() cout
More informationA few important patterns and their connections
A few important patterns and their connections Perdita Stevens School of Informatics University of Edinburgh Plan Singleton Factory method Facade and how they are connected. You should understand how to
More informationPlan. A few important patterns and their connections. Singleton. Singleton: class diagram. Singleton Factory method Facade
Plan A few important patterns and their connections Perdita Stevens School of Informatics University of Edinburgh Singleton Factory method Facade and how they are connected. You should understand how to
More informationG Programming Languages Spring 2010 Lecture 9. Robert Grimm, New York University
G22.2110-001 Programming Languages Spring 2010 Lecture 9 Robert Grimm, New York University 1 Review Last week Modules 2 Outline Classes Encapsulation and Inheritance Initialization and Finalization Dynamic
More informationCS61, Fall 2012 Section 2 Notes
CS61, Fall 2012 Section 2 Notes (Week of 9/24-9/28) 0. Get source code for section [optional] 1: Variable Duration 2: Memory Errors Common Errors with memory and pointers Valgrind + GDB Common Memory Errors
More informationDesign Pattern. CMPSC 487 Lecture 10 Topics: Design Patterns: Elements of Reusable Object-Oriented Software (Gamma, et al.)
Design Pattern CMPSC 487 Lecture 10 Topics: Design Patterns: Elements of Reusable Object-Oriented Software (Gamma, et al.) A. Design Pattern Design patterns represent the best practices used by experienced
More informationCE221 Programming in C++ Part 1 Introduction
CE221 Programming in C++ Part 1 Introduction 06/10/2017 CE221 Part 1 1 Module Schedule There are two lectures (Monday 13.00-13.50 and Tuesday 11.00-11.50) each week in the autumn term, and a 2-hour lab
More informationEPL 603 TOPICS IN SOFTWARE ENGINEERING. Lab 6: Design Patterns
EPL 603 TOPICS IN SOFTWARE ENGINEERING Lab 6: Design Patterns Links to Design Pattern Material 1 http://www.oodesign.com/ http://www.vincehuston.org/dp/patterns_quiz.html Types of Design Patterns 2 Creational
More information3. Task Group & Applying Composite Pattern
National Taipei University of Technology Object-Oriented Programming (Fall, 2007) Homework # 3 (Due: Wed., Nov. 7, 24:00) 1. Introduction In homework #3, we will assemble several tasks as a group called
More informationGraphical Interface and Application (I3305) Semester: 1 Academic Year: 2017/2018 Dr Antoun Yaacoub
Lebanese University Faculty of Science Computer Science BS Degree Graphical Interface and Application (I3305) Semester: 1 Academic Year: 2017/2018 Dr Antoun Yaacoub 2 Crash Course in JAVA Classes A Java
More informationThe Lorax Programming Language
The Lorax Programming Language Doug Bienstock, Chris D Angelo, Zhaarn Maheswaran, Tim Paine, and Kira Whitehouse dmb2168, cd2665, zsm2103, tkp2108, kbw2116 Programming Translators and Languages, Department
More informationCS304 Object Oriented Programming Final Term
1. Which of the following is the way to extract common behaviour and attributes from the given classes and make a separate class of those common behaviours and attributes? Generalization (pg 29) Sub-typing
More informationObject Oriented Software Design
Object Oriented Software Design Introduction to Object Oriented Programming Giuseppe Lipari http://retis.sssup.it/~lipari Scuola Superiore Sant Anna Pisa September 23, 2010 G. Lipari (Scuola Superiore
More informationCS304- Object Oriented Programming LATEST SOLVED MCQS FROM FINALTERM PAPERS. MC
CS304- Object Oriented Programming LATEST SOLVED MCQS FROM FINALTERM PAPERS JAN 28,2011 MC100401285 Moaaz.pk@gmail.com Mc100401285@gmail.com PSMD01 FINALTERM EXAMINATION 14 Feb, 2011 CS304- Object Oriented
More informationObject Oriented Software Design II
Object Oriented Software Design II Real Application Design Christian Nastasi http://retis.sssup.it/~lipari http://retis.sssup.it/~chris/cpp Scuola Superiore Sant Anna Pisa April 12, 2012 C. Nastasi (Scuola
More informationObject-Oriented Concepts and Design Principles
Object-Oriented Concepts and Design Principles Signature Specifying an object operation or method involves declaring its name, the objects it takes as parameters and its return value. Known as an operation
More informationQUIZ. How could we disable the automatic creation of copyconstructors
QUIZ How could we disable the automatic creation of copyconstructors pre-c++11? What syntax feature did C++11 introduce to make the disabling clearer and more permanent? Give a code example. Ch. 14: Inheritance
More informationProduced by. Design Patterns. MSc in Communications Software. Eamonn de Leastar
Design Patterns MSc in Communications Software Produced by Eamonn de Leastar (edeleastar@wit.ie) Department of Computing, Maths & Physics Waterford Institute of Technology http://www.wit.ie http://elearning.wit.ie
More informationFinancial computing with C++
Financial Computing with C++, Lecture 6 - p1/24 Financial computing with C++ LG Gyurkó University of Oxford Michaelmas Term 2015 Financial Computing with C++, Lecture 6 - p2/24 Outline Linked lists Linked
More informationLecture 20: Design Patterns II
Lecture 20: Design Patterns II Software System Design and Implementation ITCS/ITIS 6112/8112 001 Fall 2008 Dr. Jamie Payton Department of Computer Science University of North Carolina at Charlotte Nov.
More informationWhat is Design Patterns?
Paweł Zajączkowski What is Design Patterns? 1. Design patterns may be said as a set of probable solutions for a particular problem which is tested to work best in certain situations. 2. In other words,
More informationCS250 Final Review Questions
CS250 Final Review Questions The following is a list of review questions that you can use to study for the final. I would first make sure that you review all previous exams and make sure you fully understand
More informationSoftware Design Patterns. Background 1. Background 2. Jonathan I. Maletic, Ph.D.
Software Design Patterns Jonathan I. Maletic, Ph.D. Department of Computer Science Kent State University J. Maletic 1 Background 1 Search for recurring successful designs emergent designs from practice
More informationCOMP6771 Advanced C++ Programming
1 COMP6771 Advanced C++ Programming Week 11 Object Oriented Programming 2016 www.cse.unsw.edu.au/ cs6771 2 Covariants and Contravariants Let us assume that Class B is a subtype of class A. Covariants:
More informationFactory Method. Comp435 Object-Oriented Design. Factory Method. Factory Method. Factory Method. Factory Method. Computer Science PSU HBG.
Comp435 Object-Oriented Design Week 11 Computer Science PSU HBG 1 Define an interface for creating an object Let subclasses decide which class to instantiate Defer instantiation to subclasses Avoid the
More informationDesign patterns. OOD Lecture 6
Design patterns OOD Lecture 6 Next lecture Monday, Oct 1, at 1:15 pm, in 1311 Remember that the poster sessions are in two days Thursday, Sep 27 1:15 or 3:15 pm (check which with your TA) Room 2244 + 2245
More informationTecniche di Progettazione: Design Patterns
Tecniche di Progettazione: Design Patterns GoF: Builder, Chain Of Responsibility, Flyweight 1 Design patterns, Laura Semini, Università di Pisa, Dipartimento di Informatica. Builder 2 Design patterns,
More informationSeptember 10,
September 10, 2013 1 Bjarne Stroustrup, AT&T Bell Labs, early 80s cfront original C++ to C translator Difficult to debug Potentially inefficient Many native compilers exist today C++ is mostly upward compatible
More informationModellistica Medica. Maria Grazia Pia, INFN Genova. Scuola di Specializzazione in Fisica Sanitaria Genova Anno Accademico
Modellistica Medica Maria Grazia Pia INFN Genova Scuola di Specializzazione in Fisica Sanitaria Genova Anno Accademico 2002-2003 Lezione 9 OO modeling Design Patterns Structural Patterns Behavioural Patterns
More informationProgramming, numerics and optimization
Programming, numerics and optimization Lecture A-4: Object-oriented programming Łukasz Jankowski ljank@ippt.pan.pl Institute of Fundamental Technological Research Room 4.32, Phone +22.8261281 ext. 428
More information