A clear thought process helps coders to get to the solutions. This post simply walks you through my thought process of how to implement some very basic data structure - a stack and a queue.
BDD is basically TDD done properly. It is an agile methodology for building a shared understanding of what software to build by discussing using examples. It is a technique that uses a business language to define acceptance criteria. It is about figuring out what to build with an outside-in approach - having conversations, capturing conversations, automating conversations. In other words, first think about what you’re about to write, then think about how you would test the code, before writing it.
BDD is not an agile project framework (e.g. SCRUM) nor a project management approach.
State pattern is a behavioral pattern in GoF because it allows to alter its behavior when a context's internal state changes. The pattern handles each state using a separate state object and the transition from one state to another that does not call for if-then statements.
Chain of Responsibility pattern is a behavioral pattern that sends data (a request, a Command) to an concrete handler object and if that handler object can't use/handle it, it passes the data/request to other objects along the chain until an handler object handles it.
Mediator pattern is a behavioral pattern that coordinates and encapsulates many-to-many communication/interaction among related objects (Colleagues) so that Colleagues interact not directly with other independent Colleagues, but indirectly with other Colleagues through a centralized Mediator.
Bridge pattern is categorized as a structural pattern in GoF because it structurally decouples abstraction from its implementation so that the two can vary independently. However, it is very similar to Strategy pattern which is categorized as a behavioral pattern.
Strategy pattern is a behavioral pattern that lets the algorithm vary independently from clients that use it by defining a family of algorithms, encapsulate each one, and make them interchangeable. An algorithm that's encapsulated in this way is called a strategy. Strategy is concerned with changing the behavior of an object.
In this post, I note the approach and my thought process about determining whether a given smaller tree (t2) is a sub-tree of another larger tree (t1).
First, the approach: Since I know t2 is smaller and it is to be matched/found in a larger tree t1, I'll take the approach of scanning through the larger tree t1, and t1's children, by trying to find a match of t2 in t1's left child tree and find a match of t2 in t1's right child tree, recursively.
Visitor pattern is a behavioral pattern that lets you define a new operation to apply toward classes of the elements (Element Class, a.k.a. Visitable Class) without changing the classes of the elements on which it operates. The new operations are grouped together each is called a separate Visitor class.
Visitor pattern lets you add a new operation to a structure of objects (Visitable/Elements) to be traversed through, without changing the Visitable/Element on which it operates.
Visitor class separates out would-be virtual functions into a Visitor class.
Each Visitable/Element should implement an accept(Visitor) function which delegate the request to the underlying Visitor class via calling visitor.visit(this) from accept(Visitor).
Each concrete Visitor class implements a set of visit(Object) functions that does the real work for the operation to be applied to the structure of objects. Each visit(Object) function takes in a different type of concrete Visitable/Element object. The Visitor can optionally maintain a context during a traversal.
When you're asked to mark an entire row and an entire column with 0's if an element of an MxN matrix is 0, here's my thought process: