Advertisement
pharmokan

m2 OOP notes magento php Interface Abstract Extends Inherits

Nov 5th, 2020
387
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.69 KB | None | 0 0
  1. IMPLEMENTATION OF AN INTERFACE
  2. INHERIT BY EXTENDING
  3. ABSTRACT IS BOILERPLATE YOU DEFINE
  4.  
  5. plugins extend methods and do not change class itself
  6.  
  7. when to use factory:
  8. retrieve data \model class make new class
  9.  
  10. Repositories are part of the Service Contracts (they are implementations of interfaces in Api), this means they are meant as a public interface to other modules.
  11.  
  12. Factory Model in Magento 2 hold very limited data.
  13. On the Other hand, Repository Model contains all data, in case of eav attributes related to customer, products , etc.
  14.  
  15. For saving model, always use Repository to save any entity, if factory model is used for saving model, it deletes all non-system eav attributes related to that entity (customer, product, etc.).
  16.  
  17. For loading model purpose, Repository are best option to get model using getById() method.
  18.  
  19. extends INHERITS
  20. override same name methods
  21. dont worry about the other methods if no custom functionality. you can still use parent class methods on said custom class.
  22. Classes can implement an interface while inheriting from another class at the same time
  23.  
  24. Abstract
  25. When inheriting from an abstract class, all methods marked abstract in the parent's class declaration must be defined by the child;
  26. A subclass must override abstract methods or otherwise should be 'abstract' themselves.
  27.  
  28. Object Interfaces IMPLEMENTS
  29. allow you to create code which specifies which methods a class must implement, without having to define how these methods are implemented.
  30.  
  31. PHP - Interfaces vs. Abstract Classes
  32. Interface are similar to abstract classes. The difference between interfaces and abstract classes are:
  33.  
  34. Interfaces cannot have properties, while abstract classes can
  35. Like an abstract class, Interface is another way to define abstract type
  36. All interface methods must be public, while abstract class methods is public or protected
  37. All methods in an interface are abstract, so they cannot be implemented in code and the abstract keyword is not necessary
  38. To implement an interface, a class must use the implements keyword.
  39.  
  40. New instantiation of a class is an Object
  41. Variables and functions are called properties and methods respectively in OOP world.
  42. public: can be accessed anywhere.
  43. protected: can be accessed by the class and subclasses only.
  44. private: can be accessed by the class only.
  45. Static properties can be called without instantiating a new class object
  46. new class that inherits a parent class is called a SUB CLASS
  47. A subclass inherits all properties and methods from it's super (parent) class except for private ones.
  48. Parent class constructor are not implicitly called if the child class defines them as well. a call to parent::__construct() within the child constructor is required.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement