Structured development methodology in Dynamics 365 Business Central

Structured development methodology in Dynamics 365 Business Central

Show Video

Hello, and welcome, my, name is Gary winter, in, this video I will show you a structure, development, methodology. For writing code in Microsoft. Dynamics, 365. Business. Central. Our. Objectives. In this course are to, learn why. We need a structured development, methodology. For writing, repeatable, IP and, what, benefits, it brings. How. To translate, business. Requirements. Into visual studio code al, in a structured, way and. What. Principles. And elements to watch out for in order to make our code highly, understandable. Across. The complete, ecosystem of al developers. Updatable. And. Expandable. Let. Us first discuss why, it is relevant to write code in a structured, and reproducible. Way instead. Of just developing, in any individual. Way we may think of, isn't. It just enough to develop the functionality. That needs to be implemented one may ask does. It matter how it's written well. It does and it. Makes the difference between arriving. At a true software. Product, with repeatable, IP or. Not. The. Way we write code, significantly. Influences. The transparency. Testability. Update. Ability, and expandability. Of, our product and if. We look at the complete, lifecycle of, our solution, this, is exactly, what we need we. Need our code base to be easily, understandable, for other developers, and that includes. Us when we come back to our solution, after some time, we. Need it to be easy to test and update, to a new version and we. Needed to be expandable, if, only, for customizations. In a given implementation. If. We. Write our code in a structured, and reproducible. Way we. Minimize the risk for bugs and for. Things to go wrong when the code base gets updated, or, when functionality. Gets enhanced. Doing. So we reduce the total cost of ownership for the product and, for any implementation. Based on the product, and we. Allow for a wealth of well-defined, integration. And enhancement, scenarios. While. A structured, development, methodology, is beneficial, for any kind of coding it. Is a must for repeatable. IP a. Structured. Approach to writing code defines. How, to transform. Business, requirements. Into coding elements, it. Allows developers, to select, and use these coding, elements, in a very conscious, and reproducible. Way, doing. So your development, decisions, become explainable. And, understandable. For others, very easily. While. Not confining, creativity. Any. Randomness. In coding, needs to be eliminated. Creative. Coding lies in selecting, the right design patterns. Extending. Design patterns, and inventing. New design, patterns, but. Not in just writing code in any random way that may come to your mind at the moment. The. Structured development, methodology, implements. A type of coding, which can be taught, learned. Applied. And. Reviewed. There. Is a standardized, approach to, translating, any business, requirement. Into code any. Business, requirement, can always be assigned to three elements. Somebody. Always does, something, within. A given process. So. When we come upon a business requirement we. Always, need to ask ourselves these, questions first, who. Meaning. Which agent, does. What meaning. Performs. Which action, in which, context. If. You think for instance of sales posting. In Microsoft, Dynamics 365. Business, central the. Answers are easily found the. Sales header that, is the agent. Posts. That, is the action from. A document, which, constitutes. The context. We. See that the agent, the. Somebody, who does something is, almost, all, represented. By a class, or, in. Business central. /video, visual, studio code al terms a table. The. Action, is a method. Of this class as reflected. In a code unit object, and, the. Context, is normally, constituted. By a UI element, such. As a page or. Alternatively. By some background, process. You. Can break down this implementation. Model into the formula, who, does, what where. This. Formula, has a lot of analogies in communication. Sudz, such, as the five W's, in journalism. As established. By Joseph Pulitzer who. What, when, where, and why or. The. Concept, of circumstance. As defined. By the Roman statesman philosopher, and, orator, Marcus, Tullius Cicero, which. Is some. 1900. Years older, so. When. You start to put a business requirement to life all, we start by determining who. Is acting, this. Is almost always a class or a table. Then. Put, any action, into, a code unit, of its, own. Finally. Always call. An action only through. Its agent, you. Define a function on its table, and make, the function call, its code unit never. Call the code unit directly, from anywhere but from this function on the table which. Declares, it as one of its methods, the. Structure, is always, record. Dot. Do, something, where. Record is the table and do something, is a function on the table calling. A global, function of the same name in a, code unit of the, same name. This. Constitutes. An object-oriented. Approach to coding or the, visual studio code al is not an object-oriented, language, this. Is more about your development, approach and how to reflect, that development, approach in visual studio code al.

Although. The, language as such is not object-oriented. We can get pretty close in implementing, it according, to object-oriented. Principles. It. Is very important, to, replace the traditional procedural. Architecture. By this approach. We're. Not running functions. Or code units anymore, passing record variables, as parameters. We're. Letting a class, implement. Its, methods. Classes. Are normally, represented. By tables, or table, extensions, in, some, rare and well-defined. Contexts, a code unit, can, be used as a class as well. Each. Class, always, carries, all of its attributes and, methods. Attributes. Are the table fields methods, are the table functions, which, point to code units, of the same name, just. Like the attributes, all, methods. Are always, declared, on its class. This. Implementation. Methodology, has, a lot of advantages. It, not only structures. Your code in a highly transparent way but. It also makes you see immediately, and without searching, for it which, methods, exist for, each class and it. Should be clear by now that which, functions, exist for each table and which, actions are defined for which agents, are only synonyms. For that. Thus. Intelligence. Works not only for every field but. Also for all methods. Of each class. These. Methods, need to be declared, but. In most cases not. Coded. On that, class. The. General, principles, to be followed on implementing, a method are. Encapsulation. Decoupling. Readability. And. Consistency. Let. Us have a look at what that means for, coding, any sort, of method. Encapsulation. Is one of the four fundamentals. Of object-oriented. Programming. Along. With abstraction. Inheritance. And polymorphism. It. Is all about packing, functions, which belong to one method, into, a single. Component. Doing. So you hide, these functions, within an object thus. Building an, impenetrable. Wall to. Protect the code from accidental. Disruption. So. Encapsulation. Is a language, mechanism. To, restrict, access to a number of defined, components. A, more. Trivial, way of putting it would be be. As local, as possible at. All times. This. Is how the principle, of encapsulation, can be reflected, in visual studio code al. Each. Method becomes, a code unit of its own, the. Code unit always, only has one global. Function. The. Method code unit itself does not have any global, variables, or variables. Which need to be shared by functions, are passed locally. As parameters. A. Method. Is always, instantiated. Through its class which. Means that there is a global function, on the table, which, declares, the method and calls. The only global function in the code unit, in. Code. You always, only call the method through this function, on the table. Finally. Within. The method code unit each, local, function, always only. Executes. One, single, task. Let. Us turn to the next principle of implementing, methods in a structured way that. Is decoupling. Now. The value, of decoupling, is normally defined in a negative way through, the disadvantages. Of tight coupling. Coupling. Describes, the degree of interdependence.

Between Routines. Low. Coupling is a sign of well-structured, software, and good architectural. Design. This. Principle, has been introduced, by Larry Constantine in the late sixties, in his book on structure, design, Larry. Constantine is an American software engineer, and computing, pioneer, who. Has become a professor, in the center for exact science, and engineering at, the University. Of Madeira, Portugal. So. Decoupling. Actually, means providing, low, coupling, the. Need to keep coupling, of routines, and components, as low as possible is easily. Illustrated, when looking at the disadvantages. Of tight coupling in tight. Coupled, code a change. In one routine, forces. A ripple, effect of changes, in other components. Thus. Making routines, hard to reuse because. All the dependent, routines must always be, included. It. May, be a no-brainer to demand, that your code should be readable but. What exactly does that mean besides, coding, in a clean way leveraging. Design patterns, and using, standardized, naming, for variables, and functions. Well. Special, attention needs to be paid to the main function of each method, it. Should ideally, be a readable, flowchart, of what the method does it. Should include all relevant steps, wherever, that is possible, if, you find, that this appears to be impossible, you, are probably trying to squeeze, which should be more than one method into. A single, code unit. The. Main function. Of each method, should resemble. Understandable. Plain, text, more, than language. Specific, statements, if. You want to break it down into an example a function. Called get customer, is not, language specific. While. A statement, like cust, get. Is, because. The exact, syntax that, you need to implement to retrieve a customer, record from the database will, vary in any programming, language if. You. Want to operationalize. What, understandable. Plain text means just. Imagine, whether it's readable, for consultants, or long. Developers, in general or. Not. Here. Is an example of what understandable. Plain text, or a, readable. Flowcharts. Of what the method does can mean in practice. This. Is an extract from a method, which batch posts, planned costs.

See. How all the statements, only call functions, which have a name, that does not sound cryptic, or idiosyncratic. To a specific, language. Instead. They could be headlines. Indicating. A sequence, of actions which. Is understandable. To any non, developer. The. Implementation, of the methods starts, with a few error checks, you. Can also see immediately, how this way of coding helps consultants, and support imagine. A user who contends, that there is a bug in the code because. It always comes up with an error if the user has not specified a posting, date. Looking. At this code you, can make the immediate, call that this is not a bug but. Included. By design. There. May still be some argument as to whether it is necessary or not but. The way the code is implemented. Immediately. Shows, anybody, who looks at it that, the posting, date is mandatory, by design, and that, the developer, has made a conscious decision about that, you. Do not need to understand, the code as such and you, do not need to dig deeper to be able to make that call. Being. Consistent. Is a major quality, of any software and that, does not only pertain, to code. Consistency. Is a quality, that starts, in marketing, and ends. In the naming of a function, we. Need to think in terms of consistency, from marketing, to sales messaging. And documentation. Right, down to code level in, this. Example here, we are making sure that a method, which posts, accruals, is called, post accrual, on UI, level, that, is on the page but. That the method on the class is also called post, accruals, as is, the code unit which implements, the function and the one global, method within, that code unit. There. Are slight variations to. These naming conventions, let's. Suppose posting. Accruals is a method, which exists, in the context, of more, than one class or data entity, for. Instance on the sales header and on the purchase header in this. Case you would add that context, information, when necessary but, omitted. Where it is not needed, since. You would need to code units which implement, the method for the from entities one. Would need to be called post-sales. Accruals while the other one would be called post-purchase, accruals, in. The explicit, context. Of each data entity, he would however leave out the epithet, which, creates, that context, that is, sales or purchase, so. The page action, would only be called, post, rules on both, the sales order, and on, the purchase order page, that. Holds true for the method on the class and the global method function, as well. After. We have clarified the principles, that govern a structured, development, which places each piece of functional, code inside. One, encapsulated. Code unit let. Us now take a closer look at the internal. Structure of this, method code unit in. General. Your. Code is based on system, events or integration. Events published. By the Microsoft, based app which, make its code extendable. For you. So. Keep in mind to make your own code extendable, as well, preferably. Even more so than the current business central base app, make. A code easy to, extend, for. Your own dependent. Add-on apps, for. Third-party add-on. Apps which build on top of your IP and. For. Tenant specific, custom, apps written, by your reselling, partner, for, a specific implementation. Do. So by, making every, single one of your functions extendable, there. Are three different contexts. To look out for one. Rep. Every method into on before, and on after events, in which, the on before, event implements, the handle pattern. This. Makes it easy to implement a variation. Of the complete, method if that, becomes necessary in, a dependent add-on, or in, a tended specific, customization.

To. Insert. Integration, events which make it possible to enhance your, code wherever appropriate. 3. Always. Separate, the initialization, of, data from, database. Transactions. Such, as insert, or modify, by. Publishing, and enough to initialize, event before, the database, transaction. What. Is the positive effect, of that. Imagine. That an add-on adds a few fields to an existing table by means of a table extension. The. Add-on most probably, needs to assign values, to these fields, in all of the in distances, in which you assign values to the original, fields in that table, you. Will need to enable, that by allowing add-on, or custom, apps to hook into that process by, an integration. Event which, you can subscribe to before, the data gets written to the database. In. Quite, a similar, way you, should think about publishing, an integration, event whenever, you set a filter on a record set that you loop through an. Enhancement, of your app may want to set additional filters, based. On new or different, fields, I. Have. Emphasized, earlier that. Each method code unit, only, contains, one global. Function all, other, functions, are local, this. Global function does not contain any functional. Code but, only the structure, of how the functional. Code is implemented. It. Consists, of three main layers a UI. Wrapper, an event. Wrapper and the. Functional, code as such which gets implemented, by the main method, all. Of these structural, and functional elements. Are local. The. UI wrapper, consists, of a confirm, and an acknowledge, part. It. First asks, whether the function should be executed, unless. This is suppressed by a high dialog parameter, which gets passed to the function or, by the fact that we are in a context, in which no UI is allowed. The. Final, acknowledge part of the UI wrapper gives, information on, whether the function was executed properly and with, what result. The. UI wrapper is optional, there are a lot of cases in which no confirm nor acknowledge would, make any sense, there, are also a lot of cases in which just, the acknowledge, is not necessary. If. You include a UI wrapper you should always include, a high dialog, parameter, to, enable, the execution, of the method with, or, without, a user interface. The. Event wrapper makes it possible for an add-on, or tenant specific, extension, based, on your app to, implement, a variation. Of your method, the. On before, event wrapper publishes. A business, or integration event, implementing. The handle pattern. If. An extension, based on your app subscribes. To this event and sets handle to true the. Main method, needs to respect, this and not, execute. If a, variation, of the method has already been executed. That. Is why every main method, needs to begin with a statement if, handled, then. Exit, the. Main. Method, finally, is what has been called a readable, flowchart, of your method, containing. All relevant, steps, as local sub functions, which, have names that resemble, understandable. Plain, text.

This. Is an example, of what, the structure of the global function, looks like in Visual Studio code, al. And. Here. You see the complete structure, of a method code unit exemplified. In Visual, Studio code al, containing. All of its building blocks. It. Is, more a matter of taste whether, you want to place your business extensions, before or, after, the event wrapper. It. Is also entirely up to you whether you want to implement, the event wrapper as business. Events, or integration, events the functionality. Is exactly, the same. Implementing. Them as business, events, implies, that you will never change the, contract, established, through them. This. Is probably a very hard call to make. Implementing. The wrapper events as business, events. Also. Sets them apart from the integration. Events, which constitute. An enhancement. Of your original, code instead, of an override, of your method. This. Does make some sense but. It is not in keeping with the or original, definition of how business, events are to be used if you do not intend, to permanently. Keep the structure as it, is. Finally. Let. Us have a look at the structural, elements, which make up the main method, of a method code unit. Surprisingly. Or, unsurprisingly. Enough. You, will find that the business process, part of a method code unit always. Consists. Of the same elements. These. Are usually elements. Which, perform. A validity check that. Is check whether a method is valid in the current context, or not and if, not exit, or thrown error. Define. A filter. Loop. Through a number, of Records. Assign. You or modified, values, to these records. Or. Perform. Database, operations, on these records. Any. Code. You write can. Normally, be assigned to one of these element categories. In, the light of the fact that one function should only ever be designed, to accomplish one, task it, is, advisable to put, all of the code for these elements, into separate functions, have. One local, function that defines a filter, another. Local function that loops through the filter. One. Function that assigns values, to a record and another. Function that performs the database operations. Also. Make these reappearing. Structural, elements, visible, by, giving them similar, names in each code unit it, will, give you and other developments. A great, sense, of structure, across, your complete code base and help, you to arrive at a structured, and unified, way of translating. Business requirements. Into, business central code. This. Concludes our course on structure, development methodology. We. Have learned why a structured, development methodology, is an essential, prerequisite, for writing repeatable, IP, how. It can be used to translate business, requirements, into code and what. Principles, and elements to look out for and implement. To. Learn more about how to build and publish apps with Microsoft, our name is 365 business central follow. The link on the, screen.

2018-09-25 10:36

Show Video

Other news